From my blog post about redirecting to certain versions: https://bashy.im/blog/nginx-redirect-to-https-with-without-www-subdomain
server {
listen 80 http2;
listen [::]:80 http2;
server_name www.example.com example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/nginx/certs/example.crt;
ssl_certificate_key /etc/nginx/certs/example.key;
# Ciphers and protocols
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Excludes SSLv2/3
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; # Current at the time of Feb 2016
ssl_prefer_server_ciphers on;
server_name example.com;
return 301 https://www.example.com$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/nginx/certs/example.crt;
ssl_certificate_key /etc/nginx/certs/example.key;
# Ciphers and protocols
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Excludes SSLv2/3
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; # Current at the time of Feb 2016
ssl_prefer_server_ciphers on;
server_name www.example.com;
[...]
}