Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebastian13/2e85fb6be13a3f2204d6c6c351dab54c to your computer and use it in GitHub Desktop.
Save sebastian13/2e85fb6be13a3f2204d6c6c351dab54c to your computer and use it in GitHub Desktop.
Redirect any server_name to the first one defined
server {
listen 80;
listen [::]:80;
server_name example.com 1.example.com;
# Redirect all HTTP links to the matching HTTPS page
location / {
return 301 https://$host$request_uri;
}
}
server {
server_name example.com 1.example.com;
listen 443 ssl http2 ;
ssl_certificate /etc/nginx/ssl/live/example.com/fullchain.pem;
ssl_certificate_key /etc/nginx/ssl/live/example.com/privkey.pem;
ssl_trusted_certificate /etc/nginx/ssl/live/example.com/chain.pem;
# Forward to the first Server Name
# https://stackoverflow.com/a/40411590
if ($host != $server_name) {
rewrite ^/(.*) $scheme://$server_name/$1 permanent;
}
location / {
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment