Skip to content

Instantly share code, notes, and snippets.

@solancer
Last active January 8, 2022 14:59
Show Gist options
  • Select an option

  • Save solancer/959db1f99007da8876545b503e9ecf53 to your computer and use it in GitHub Desktop.

Select an option

Save solancer/959db1f99007da8876545b503e9ecf53 to your computer and use it in GitHub Desktop.
Configure Nginx SSL + force HTTP to redirect to HTTPS + force www to non-www
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