I’ll show you how to quickly and easily enable IPv6 support in Nginx.
Let’s assume that the IPv6 address for the server has already been received and there are configurations of several sites in nginx:
server {
listen 80 default_server;
server_name ixnfo.com;
return 301 https://$server_name:443$request_uri;
}
server {
listen 443 ssl default_server;
...
}
server {
listen 80;
server_name ixnfo2.com;
return 301 https://$server_name:443$request_uri;
}
server {
listen 443 ssl;
...
}
Now, to make nginx listen for connections on the IPv6 address, simply add to the configuration:
listen [::]:80;
listen [::]:443;
For example:
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name ixnfo.com;
return 301 https://$server_name:443$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
...
}
server {
listen 80;
listen [::]:80;
server_name ixnfo2.com;
return 301 https://$server_name:443$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
...
}
By the way, the default_server parameter is specified only for one site, it cannot be specified more than once, it is needed, for example, when there is no configuration for some domain, then the web server will use the configuration where default_server.
Let’s check the correctness of the configuration, restart nginx and check the availability of the site via IPv6:
nginx -t
systemctl restart nginx
curl -6 http://ixnfo.com
See my other articles about nginx