Skip to content

Instantly share code, notes, and snippets.

@shime shime/ngnix.conf
Created Oct 31, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.