Last active
January 8, 2022 14:59
-
-
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
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
| 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