I'm using nginx 1.4.1 (now, before it was 1.2.1) and would like to support dual stack (IPv4 and IPv6). I'm always getting duplicate listen options for xyz
errors from nginx.
server {
listen 80 default_server;
listen [::]:80 ipv6only=on default_server;
server_name domain1;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl ipv6only=on default_server;
server_name domain1;
}
server {
listen 80;
listen [::]:80 ipv6only=on;
server_name domain2;
}
server {
listen 443 ssl;
listen [::]:443 ssl ipv6only=on;
server_name domain2;
}
If I use only listen 80
I'm getting only IPv4. Otherwise if I use listen [::]:80
I'm getting only IPv6.
How to setup nginx 1.4.x to support virtual host dual stack?
You've used(Or you did, until you edited this part out.)default_server
in more than oneserver
block. This is only meant to be used to define the default virtual host for a given IP address/port combination. So it should appear only once per IP/port pair in your entire configuration. Which host should be the default virtual host is up to you.Also,
ipv6only
can appear only once in the entire configuration. Since its default in 1.4 and higher ison
, you can safely omit it entirely.