Listen on both IPv4 and IPv6
This is kind of the universal Nginx configuration. It will listen on both IPv4 and IPv6.
server {
listen 80;
listen [::]:80;
server_name example.com;
root /var/www/example.com;
}
I ended up with the following configuration for my pxy.fi site.
server {
listen 80 default_server;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name pxy.fi;
# Other stuff going on here
}
First I redirect all HTTP requests to HTTPS. And I listen on both IPv4 and IPv6.
There is some discussion about this on ServerFault, but I went with the separation of the two directives since it is easier to read.