# Redirect non-www to www over HTTPS
server {
listen 80;
listen [::]:80;
server_name domain.com;
return 301 https://www.domain.com$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name domain.com;
ssl_certificate /path/to/ssl_certificate.crt;
ssl_certificate_key /path/to/ssl_certificate.key;
return 301 https://www.domain.com$request_uri;
}
# Serve www.domain.com over HTTPS
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.domain.com;
ssl_certificate /path/to/ssl_certificate.crt;
ssl_certificate_key /path/to/ssl_certificate.key;
root /path/to/your/website;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ =404;
}
}