Nginx Optimal SSL settings on Ubuntu 14.04

Below is how to configure Nginx for optimal SSL settings. These settings are directly from Mozilla’s recommend best practice page and were current as of the date of this post. Please refer to that site for the most current settings.

This post assumes that you already have a and you are working with the domain

  1. Generate your certificate request (CSR)
    sudo openssl req -nodes -newkey rsa:2048 -keyout /etc/nginx/ssl/ -out /etc/nginx/ssl/
  2. Get a cert with the CSR above. I use for my certs since they’re cheap, fast and they do the job. Some people think that you need to get a cert from a big name place like DigiCert or Thawte but in reality, consumers don’t care (let alone understand) so I don’t see a reason to pay extra. There’s a push to get EV (green bar) certs which I understand but still, most people just don’t seem to care.
  3. Assuming you went with the above you’ll get an email with your cert files. However, I usually just log back into my account, navigate to my cert and re-download the certificate which should have a zip file with two files, and bundle.crt. Both files are just text files so either copy or create and write both of them to /etc/nginx/ssl/
  4. Create this file, I’m not going to bother explaining it because I don’t fully understand it either:
    sudo openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048
  5. Edit your site’s previously created configuration file:
    sudo vi /etc/nginx/sites-available/

    # Optional, redirect non-secure connections to the secure site
    server {
        listen         80;
        return 301 https://$host$request_uri;
    server {
        listen 443;
        #Your path here
        root /var/www/html;
        #Your domain here
        ssl on;
        ssl_certificate     /etc/nginx/ssl/;
        ssl_certificate_key /etc/nginx/ssl/;
        ssl_dhparam /etc/nginx/ssl/dhparam.pem;
        ssl_session_timeout 5m;
        ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        ssl_session_cache shared:SSL:50m;
        ssl_stapling on;
        ssl_stapling_verify on;
        ssl_trusted_certificate /etc/nginx/ssl/bundle.crt;
        #Your other rules here
  6. Test your configuration:
    sudo nginx -t
  7. Reboot Nginx:
    sudo service nginx restart

These settings should give you (as of this posting date) an A grade but not 100% across the board at Qualys SSL Labs. To do that you need to fix some other edge cases but even Qualys SSL Labs doesn’t seem to want to fix so I’m not too concerned.

Once again, and I can’t stress this enough, DO NOT JUST COPY THE ABOVE but actually go out to Mozilla’s or someone else’s site to get a list of currently recommend cipher suites and protocols, especially as this post gets older and older.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.