8

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?

1
  • It's not very clear in the answers here, but ipv6only now defaults to enabled if you are using the single-line listen directive in your question example. It's better to explicitly define a listen line for both IPv4 and another for IPv6, and the you don't need to worry about ipv6only at all (delete the phrase if exists). Aug 1, 2022 at 16:13

2 Answers 2

11

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;

and

    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;
9
  • What listen block did you write in the other servers? For my all requests to the other servers on IPv4 end up on the default_server. May 30, 2013 at 20:22
  • It's in /etc/nginx/conf.d/default.conf which serves the server_name _. If you're having trouble, check nginx's error log; if you just did a service nginx reload it will say OK even if the configuration file check failed. May 30, 2013 at 20:24
  • Sorry, I don't understand. What exactly did you add to /etc/nginx/conf.d/default.conf? May 30, 2013 at 20:30
  • I put the above listen directive in that particular server block. The rest I left untouched. May 30, 2013 at 20:33
  • Ah, ok because I have my server configs in /etc/nginx/sites-available resp. /etc/nginx/sites-enabled. May 30, 2013 at 20:38
4

An alternative to @Michael Hampton's answer (but you have to touch all files) is to insert

listen 80;      # listen for IPv4
listen [::]:80; # listen for IPv6

for all servers.


Strange is, that inserting listen [::]:80 ipv6only=off for more than one server results in

nginx: [emerg] duplicate listen options for [::]:80 in /etc/nginx/sites-enabled/default.conf:3

And a mix of listen 80; and ipv6only=off (in different servers) results in

nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .