How to disable ipv6 in nginx?

rough lea roughlea at hotmail.co.uk
Thu Nov 15 14:36:48 UTC 2018


Hi Francis and Maxim,

Cheers, that solved it. Used 127.0.0.1 and works like a charm. Will remove the resolver from my config. 

Thanks for the explanations.

Kind regards

Simon 

> On 15 Nov 2018, at 14:24, Maxim Dounin <mdounin at mdounin.ru> wrote:
> 
> Hello!
> 
> On Thu, Nov 15, 2018 at 11:10:08AM +0000, rough lea wrote:
> 
>> 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…..
> 
> [...]
> 
>>    proxy_pass  http://localhost:1080/files/;
> 
> [...]
> 
>> If I take out the line, _listen                          
>> [::]:1081 http2 ipv6only=on ssl;_ from the server config block, 
>> the issue still occurs. 
> 
> The error is about connecting to "[::1]:1080" backend, as per 
> proxy_pass in your configuration.  Adding or removing listening 
> sockets in nginx is not expected change things.
> 
>> 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???
> 
> The error (Address not available) suggests that this is indeed an 
> issue in Docker.
> 
>> 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. 
> 
> When a name is known during configuration parsing, nginx will 
> use normal system-provided name resolution, as available via 
> the getaddrinfo() function.
> 
> A resolver is only used once nginx does a run-time resolution of 
> domain names, and cannot use getaddrinfo() as the interface is 
> blocking.
> 
>> How can I get nginx to use ipv4 only? Has anybody else 
>> experienced and resolved the same issue?
> 
> The is no way to globally disable IPv6 in nginx.  Instead, 
> consider one of the following options:
> 
> - when you want nginx to use IPv4 addresses only, use names which 
>  resolve to IPv4 addresses only (or use IPv4 addresses directly);
> 
> - configure your system resolver to do not return IPv6 addresses 
>  (usually this happens automatically when you do not have IPv6 
>  configured on the host).
> 
> In your particular case, writing something like
> 
>   proxy_pass http://127.0.0.1:8080/files/;
> 
> with "127.0.0.1" IPv4 address explicitly used instead of 
> "localhost" should be enough.
> 
> -- 
> Maxim Dounin
> http://mdounin.ru/
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx



More information about the nginx mailing list