Created
January 21, 2020 14:48
-
-
Save jyunderwood/2981df2a83b6835a72431a6c8e412575 to your computer and use it in GitHub Desktop.
Certbot + redirects
This file contains 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
# /etc/nginx/snippets/letsencrypt.conf | |
location ^~ /.well-known/acme-challenge/ { | |
default_type "text/plain"; | |
root /srv/www/letsencrypt; | |
} | |
# Hide /acme-challenge subdirectory and return 404 on all requests. | |
location = /.well-known/acme-challenge/ { | |
return 404; | |
} |
This file contains 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
# /etc/nginx/conf.d/tld_redirects.conf | |
server { | |
listen 443 ssl http2; | |
server_name example.com; | |
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; | |
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains"; | |
include snippets/letsencrypt.conf; | |
location @redirect { | |
return 301 https://www.example.com$request_uri; | |
} | |
try_files $uri @redirect; | |
} | |
server { | |
listen 80; | |
server_name example.com; | |
include snippets/letsencrypt.conf; | |
location @redirect { | |
return 301 https://www.example.com$request_uri; | |
} | |
try_files $uri @redirect; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment