Skip to content

Instantly share code, notes, and snippets.

@bjornjohansen
Created November 13, 2016 13:37
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bjornjohansen/02429a0bda79d3e8230ea05573965776 to your computer and use it in GitHub Desktop.
Save bjornjohansen/02429a0bda79d3e8230ea05573965776 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 www.domain.tld domain.tld;
if ($host=='domain.tld') {
return 301 https://www.domain.tld$request_uri;
}
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