-
-
Save myh-st/d52d4c2a092a038b0827f3ecca9fc320 to your computer and use it in GitHub Desktop.
NGINX config for SSL with Let's Encrypt certs
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
user nginx; | |
worker_processes auto; | |
error_log /var/log/nginx/error.log; | |
pid /run/nginx.pid; | |
# Load dynamic modules. See /usr/share/nginx/README.dynamic. | |
include /usr/share/nginx/modules/*.conf; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
server { | |
listen 80; | |
listen [::]:80; | |
server_name www.myh-st.xyz myh-st.xyz; | |
return 301 https://$host$request_uri; | |
} | |
# SSL configuration | |
server { | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; | |
server_name www.myh-st.xyz myh-st.xyz; | |
ssl_certificate /etc/letsencrypt/live/myh-st.xyz/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/myh-st.xyz/privkey.pem; | |
# Improve HTTPS performance with session resumption | |
ssl_session_cache shared:SSL:10m; | |
ssl_session_timeout 10m; | |
# Enable server-side protection against BEAST attacks | |
ssl_protocols TLSv1.2; | |
ssl_prefer_server_ciphers on; | |
ssl_ciphers "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384"; | |
# RFC-7919 recommended: https://wiki.mozilla.org/Security/Server_Side_TLS#ffdhe4096 | |
ssl_dhparam /etc/ssl/ffdhe4096.pem; | |
ssl_ecdh_curve secp521r1:secp384r1; | |
# Aditional Security Headers | |
# ref: https://developer.mozilla.org/en-US/docs/Security/HTTP_Strict_Transport_Security | |
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains"; | |
# ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options | |
add_header X-Frame-Options DENY always; | |
# ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options | |
add_header X-Content-Type-Options nosniff always; | |
# ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection | |
add_header X-Xss-Protection "1; mode=block" always; | |
# Enable OCSP stapling | |
# ref. http://blog.mozilla.org/security/2013/07/29/ocsp-stapling-in-firefox | |
ssl_stapling on; | |
ssl_stapling_verify on; | |
ssl_trusted_certificate /etc/letsencrypt/live/myh-st.xyz/fullchain.pem; | |
resolver 1.1.1.1 1.0.0.1 [2606:4700:4700::1111] [2606:4700:4700::1001] valid=300s; # Cloudflare | |
resolver_timeout 5s; | |
# Required for LE certificate enrollment using certbot | |
location '/.well-known/acme-challenge' { | |
default_type "text/plain"; | |
root /var/www/html; | |
} | |
location / { | |
root /var/www/html; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment