Enabling IPv6 connectivity in Nginx is very easy, providing you already have a valid IPv6 connection/IP on your server. You should normally already have a configuration as follows.
server {
listen 80;
server_name a.b.c;
}
First, verify that your nginx is configured for IPv6.
# nginx -V
... --with-ipv6 ...
On Nginx 1.11.5 and later the –with-ipv6 flag is gone: IPv6 support is compiled in by default, so there’s nothing to check for anymore. The grep above only applies if you’re running an older build.
Now, you can change your nginx configuration file to enable IPv6. To create server-block that listens on all available IPv6 IPs as well as IPv4, add this.
server {
listen 80;
listen [::]:80;
server_name a.b.c;
}
If you want a server-block that only listens on IPv6 and not IPv4, make use of the ipv6only flag.
server {
listen [::]:80 ipv6only=on;
server_name a.b.c;
}
Note that ipv6only=on has been the default since Nginx 1.3.4, so on any modern build a plain listen [::]:80; already accepts IPv6 only. The flag can only be set once per port (on the first server-block to bind it), so spelling it out explicitly is mostly for clarity now.
Binding IPv6 on a single IP can also be done as such.
server {
listen [2a03:a800:2:1::1]:80 ipv6only=on;
server_name a.b.c;