The perfect SSL NGINX configuration


Last Updated: 11/10/2017

At we make sure we are always on top of any potential security exploits or vulnerabilities. Unfortunately, lately there has been a steady stream of SSL related issues (Heartbleed and POODLE come to mind). Fortunately patching some of the most prominent issues only requires updating a few NGINX directives.

We figured we would share our SSL NGINX configuration blocks which are used on all web servers. Let's break the NGINX directives into two logical sections. The first being security and the second related to performance and optimization.

http {  
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/ssl/dhparam.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

The above configuration provides robust perfect forward secrecy and mitigates against POODLE by removing SSLv3 support. It should also result in an A rating on Qualys SSL LABS as well. If you'd like an A+ rating, you'll need to implement strict transport security as well.

See the SSL LABS report at:

Note: This cipher suite does prevent some older clients (specifically IE6 on Windows XP) from establishing connections, but the majority of our traffic comes from users on Chrome so this is a non-factor for us. Evaluate your requirements by looking at your own traffic.

http {  
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate /etc/nginx/ssl/stapling.trusted.crt;  
    resolver valid=300s;
    resolver_timeout 10s;

    ssl_session_cache shared:SSL:32m;
    ssl_buffer_size 8k;
    ssl_session_timeout 60m;
    ssl_session_tickets off;

server {  
    # you may replace spdy with http2 if your version of NGINX supports HTTP/2
    listen 443 deferred ssl spdy;

The first set of performance directives enables OCSP stapling. We've written a dedicated blog post on OCSP stapling previously, so check that out for more information.

Next, we enable NGINX SSL cache, which provides SSL session resumption support. We allocate a shared 32MB of space (one megabyte can store about 4000 sessions according to the NGINX documentation). We set a 60 minute timeout on SSL sessions and also set ssl_buffer_size to 8K to minimize time to first byte (the NGINX default is 16K).

Finally, in the server block we enable the deferred directive and turn on SPDY support. You may replace spdy with http2 if your version of NGINX supports HTTP/2. Verify that SPDY is enabled on your site with SPDYCheck a great service by zoompf.

We'd also like to recommend a great service we recently found and signed up for called Snitch. Snitch will automatically check your SSL certificate and configuration at specified intervals. It looks for upcoming expiration, security issues, and performance recommendations and then alerts you of anything that needs attention.