Globally setting ipv6only=off

white_gecko asked:

Since an update my nginx server is only available via IPv6 and not IPv4 while my config contained

listen   [::]:80 default_server;

Now I’ve changed this to

listen   [::]:80 default_server ipv6only=off;

and the server is available via IPv4 again.
This seams to be due to the changes in nginx 1.3.4 (section “Changes with nginx 1.3.4”).

Since I have more than one server configuration on the same mashine I would like to set the ipv6only=off globally is there any possibility to do so?

My answer:

I just went through this with an upgrade from 1.0 to 1.4.

Since only a single listener is actually bound to any given port, it’s sufficient to specify ipv6only=off in any one of your listen directives.

So, in my default server blocks, I have:

    listen [::]:80 ipv6only=off default_server;


    listen [::]:443 ipv6only=off default_server;

All of the other server blocks merely specify the original listen directives. And it works; any virtual host is reachable via either IPv4 or IPv6.

You could also add it to all of them, but that’s not really required. Adding it to any one of them is sufficient.

However, because the ipv6only= flag is Linux-only, I do not use this construct anymore. My current directives specify both IPv4 and IPv6 explicitly, such as:

listen [::]:80 default_server;
listen 80 default_server;

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.