Skip to content

Instantly share code, notes, and snippets.

@svenluijten
Created January 27, 2016 13:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save svenluijten/cda825e93c9f4dddc2b6 to your computer and use it in GitHub Desktop.
Save svenluijten/cda825e93c9f4dddc2b6 to your computer and use it in GitHub Desktop.
Brilliant nginx config redirecting to non-www https by @jaw-sh.
server {
listen 80 default_server; # Listen for regular HTTP requests
listen [::]:80 default_server; # Handle requests over IPv6
server_name _; # Respond to any and all server_names
return 301 https://$host$request_uri; # Redirect to https
}
server {
listen 443; # Respond to HTTPS
listen [::]:443; # IPv6 HTTPS
server_name "~^www\.(.*)$" ; # Check if www is in URL
return 301 https://$1$request_uri; # Redirect to non-www
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment