Nginx SSL configuration

As a disclaimer, this blog isn’t really something a lot of people read, but for the few visitors that pop by, I have moved on to a network engineering job from my previous systems administration job, so I might focus less on powershell than previously, although of course it’ll remain a part of what I do.

So I’ve been toying around with letsencrypt to secure my personal homepage palmar.org. The service works quite well. I decided to see if I could secure my web server properly using the letsencrypt certificate, and it was actually relatively simple.

There’s just a few things to take care of when you’ve installed the certificate (which I’m not going to cover).

First, you need to point your ssl listener to the certificate and it’s private key:

 ssl on;
 ssl_certificate /etc/ssl/palmar.org/fullchain.pem;
 ssl_certificate_key /etc/ssl/palmar.org/privkey.pem;

Second, you have to configure the preferred encryption algorithms the server presents to the client. This list is an ever changing beast as vulnerabilities emerge, so what works today (5. december 2015) might not be relevant in a year or two. We’ll make sure our most preferred algorithms support perfect forward secrecy and are secure.

Also, it’s a good idea to disable SSLv3 and older protocols.

 ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

 ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4';

Third, it’s not enough to just prefer secure algorithms, we actually have to secure our Diffie-Hellman key exchange. To make a long story short, DH works by the client and the server exchanging prime numbers in order to obtain perfect forward secrecy. The larger the prime number group used in generating the keys, the more difficult it is to break. Commonly DH groups would be 512 or 1024 bits, but we’ll generate a 2048 bit DH group to completely secure our server. We’ll do this using openssl.

openssl dhparam -out dhparams.pem 2048

If you want to read more on this subject, here’s an excellent resource: https://weakdh.org/

We’ll then point to our newly created DH group in the server configuration:

 ssl_dhparam /etc/ssl/DH/dhparams.pem;

Finally we’re going to enable HTTP Strict Transport Security with a reasonably long duration.

 add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";

And voila, we’re done!

Looks good, doesn’t it? 🙂

Here’s the entire configuration:

 

server {
 listen 443;
 server_name palmar.org;

 root /var/www/html;
 index index.html index.htm;

 ssl on;
 ssl_certificate /etc/ssl/palmar.org/fullchain.pem;
 ssl_certificate_key /etc/ssl/palmar.org/privkey.pem;

 ssl_session_timeout 5m;

 ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

 ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4';
 ssl_dhparam /etc/ssl/DH/dhparams.pem;
 ssl_prefer_server_ciphers on;

 add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
}

 

Advertisements
Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: