Secure your Nginx server with SSL/TLS.
Nginx is known for its performance and elegant SSL configuration. A well-optimized configuration gives you security and speed.
This guide gives you a production-ready configuration with current best practices.
We cover settings to achieve an A+ on SSL Labs while maintaining compatibility.
Key directives for SSL/TLS:
Why Nginx excels at SSL:
SSL setup on Nginx:
Modern HTTPS server block:
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;
# Modern protocols
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
# Session cache
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
# HSTS
add_header Strict-Transport-Security "max-age=63072000" always;
# OCSP Stapling
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
}
# HTTP redirect
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
http2 enables HTTP/2. ssl_session_tickets off for perfect PFS.
Optimize your Nginx:
Add http2 in listen directive: listen 443 ssl http2;
Check certificate format and that the key matches.
Use nginx -t to see the syntax error.
Nginx 1.13+ and OpenSSL 1.1.1+ natively support TLS 1.3.
Cache stores server-side, tickets client-side. Disable tickets for PFS.
Use SSL Labs (ssllabs.com/ssltest) or testssl.sh.
Nginx offers excellent SSL performance with a well-optimized configuration.
Monitor your certificates with MoniTao to be alerted before any expiration.
Start free, no credit card required.