How to disable ipv6 in nginx?

rough lea roughlea at hotmail.co.uk
Thu Nov 15 11:10:08 UTC 2018


Hi,


I am a newbie running tusd server on macos High Sierra behind an Nginx Proxy running within a docker container. In the logs, I notice that before an _UploadCreated_ event is received there is an attempt to connect to tusd using ipv6 loopback address which fails. 

_[crit] 23#23: *4 connect() to [::1]:1080 failed (99: Address not available) while connecting to upstream, client: 172.22.0.1, server: , request: "POST /files/ HTTP/1.1", upstream: "http://[::1]:1080/files/", host: "test.example.com:1081"_

My nginx configuration is listed below…..

```
server {
  listen                          1081 ssl http2;
  #listen [::]:443 http2 ipv6only=on ssl;
  charset                         utf-8;

  access_log                      /dev/stdout;
  error_log                       /dev/stdout;

  ssl_certificate                 /server/certs/tls.crt;
  ssl_certificate_key             /server/certs/tls.key;

  location /files/ {

    resolver 8.8.8.8 4.2.2.2;
    #resolver 8.8.8.8 4.2.2.2 ipv6only=off;

    proxy_pass  http://localhost:1080/files/;
    #proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;

    # Disable request and response buffering
    proxy_request_buffering  off;
    proxy_buffering          off;
    proxy_http_version       1.1;

    # Add X-Forwarded-* headers so that response can reference https and
    # originating host:port
    proxy_set_header X-Forwarded-Host $host:$server_port;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    # Allow proxying of websockets if required
    proxy_set_header         Upgrade $http_upgrade;
    proxy_set_header         Connection "upgrade";
    client_max_body_size     0;
  }
```

If I take out the line, _listen                          [::]:1081 http2 ipv6only=on ssl;_ from the server config block, the issue still occurs. 

Upon further reading at [docker](https://docs.docker.com/config/daemon/ipv6/) and [docker-for-mac](https://github.com/docker/for-mac/issues/1432), it appears that ipv6 networking is only available for docker daemons running on Linux hosts???

I have tried adding a resolver and setting ipv6only=off but nginx seems to continue to try and send to the upstream proxy with an ipv6 address. 

How can I get nginx to use ipv4 only? Has anybody else experienced and resolved the same issue?


Kind regards

Simon


More information about the nginx mailing list