Skip to content

Instantly share code, notes, and snippets.

@shime
Created October 31, 2014 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shime/b54a759f297a7933450b to your computer and use it in GitHub Desktop.
Save shime/b54a759f297a7933450b to your computer and use it in GitHub Desktop.
redirect non-www to www with or without ssl in ngnix
# 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