Created
October 31, 2014 10:29
-
-
Save shime/b54a759f297a7933450b to your computer and use it in GitHub Desktop.
redirect non-www to www with or without ssl in ngnix
This file contains hidden or 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
# http://domain.com -> https://www.domain.com | |
# http://www.domain.com -> https://www.domain.com | |
server { | |
listen 80; | |
server_name domain.com www.domain.com; | |
return 301 https://www.domain.com$request_uri; | |
} | |
# https://domain.com -> https://www.domain.com | |
server { | |
listen 443 ssl; | |
server_name domain.com; | |
ssl_certificate /data/unified.crt; | |
ssl_certificate_key /data/my-private-decrypted.key; | |
return 301 https://www.domain.com$request_uri; | |
} | |
server { | |
listen 443 ssl; | |
server_name www.domain.com; | |
ssl_certificate /data/unified.crt; | |
ssl_certificate_key /data/my-private-decrypted.key; | |
location / { | |
proxy_pass http://domain.com:3000; | |
proxy_http_version 1.1; | |
proxy_set_header Upgrade $http_upgrade; | |
proxy_set_header Connection 'upgrade'; | |
proxy_set_header Host $host; | |
proxy_cache_bypass $http_upgrade; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment