Created
January 27, 2016 13:48
-
-
Save svenluijten/cda825e93c9f4dddc2b6 to your computer and use it in GitHub Desktop.
Brilliant nginx config redirecting to non-www https by @jaw-sh.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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