Skip to content

Instantly share code, notes, and snippets.

@itoonx
Created March 2, 2018 14:56
Show Gist options
  • Save itoonx/ddccbab95f2f3babf4faf5ae3babc468 to your computer and use it in GitHub Desktop.
Save itoonx/ddccbab95f2f3babf4faf5ae3babc468 to your computer and use it in GitHub Desktop.
Nginx - redirect http to https
server {
listen 80;
server_name www.domain.com domain.com;
# redirects both www and non-www to ssl port with http (NOT HTTPS, forcing error 497)
return 301 http://domain.com$request_uri;
}
server {
listen 433 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name domain.com;
error_page 497 https://domain.com$request_uri;
include snippets/ssl-domain.com.conf;
include snippets/ssl-params.conf;
# other vhost configuration
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment