Skip to content

Instantly share code, notes, and snippets.

@bjornjohansen
Created November 13, 2016 13:34
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save bjornjohansen/b5a763a57a460edac47c8560502f6400 to your computer and use it in GitHub Desktop.
Save bjornjohansen/b5a763a57a460edac47c8560502f6400 to your computer and use it in GitHub Desktop.
One nginx host file which handles domain.tld and www.domain.tld with and without https and redirects all of them to use https and www
server {
listen 80;
listen [::]:80;
server_name domain.tld www.domain.tld;
return 301 https://www.domain.tld$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name domain.tld;
return 301 https://www.domain.tld$request_uri;
# include your HTTPS config here
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name www.domain.tld;
root /whatever/your/webroot/is;
# include your HTTPS config here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment