Configuring https on nginx

Best practices for https configuration has changed through 2013. Because of BEAST attacks on TLS, RC4 had been getting prioritised by many.


  • client side mitigations to BEAST
  • strong indications that RC4 is broken
  • an increase in the use of PFS
  • (at last ) the end of Windows XP

Mean that we can prioritise some more modern ciphers.

Mozilla has produced an useful document that they recommend for their TLS web server configuration.

created some new directories beneath /etc/nginx

mkdir -p /etc/nginx/ssl/{public,private,dh}
chmod 700 /etc/nginx/ssl/private

generated a new private keys and certificate signing request

cd /etc/nginx/ssl/private
openssl req -new -newkey rsa:2048  -nodes -keyout -out 
chmod 400 # the private key needs to be private

Sent the csr off to gandi, and after domain validation recieved a x509 certificate.

This saved as into /etc/nginx/ssl/public, additionally the gandi intermediate certificate is required, so that is downloaded into /etc/nginx/ssl/public/gandi.pem.

These are then concatenated together.

cd /etc/nginx/ssl/public; cat gandi.pem > new.pem; cp new.pem

Generate a Diffie Hellman Prime

To make use of PFS we need a generate a Diffie Hellman Prime.

cd /etc/nginx/ssl/dh; openssl dhparam -out dh.pem 2048

Configure nginx

Add the following to you ssl server block. This is different to the Mozilla recommendations, I've removed support for SSL3

server {
  listen              443 ssl;
  ssl_certificate     /etc/nginx/ssl/public/;
  ssl_certificate_key /etc/nginx/ssl/private/;
  ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
  ssl_dhparam /etc/nginx/ssl/dh/dh.pem;
  ssl_session_timeout 5m;
  ssl_prefer_server_ciphers on;
  ssl_session_cache shared:SSL:50m;

  # Enable this if your want HSTS (recommended, but be careful)
  add_header Strict-Transport-Security max-age=15768000;
  # ... Rest of configuration here  
  # ... 
  # ...