An A+ SSL setup using Nginx and Letsencrypt

Back in 2014 I wrote about getting an A+ on SSL Labs using StartSSL. Much has changed since then, for starters we can now use the awesome Letsencrypt to get our certificates.

Letsencrypt is completely free, just like StartSSL, but it will only give out certificates that are valid for 90 days. Luckily you can renew your certificate just as easily as creating one.

Let’s talk about how to configure Nginx to get that precious A+ on SSL Labs.

Setting up Letsencrypt

First we need to install Letsencrypt. Well, not really because there’s nothing to install. Letsencrypt is very portable.

git clone

Requesting a certificate

There’s a few ways to request a certificate because it needs to be verified during the request process. Because I already have a web server running on port 80 I use the webroot method which places a small file in your webroot.

sh /root/letsencrypt/letsencrypt-auto certonly --webroot --webroot-path /the/path/of/my/webroot --domains,, --agree-tos --email

This will request a certificate and put it in /etc/letsencrypt/live/

Generating DH params

Before actually configuring Nginx we’ll need to set up our DH params:

openssl dhparam -out /etc/nginx/dhparam.pem 4096

Setting up Nginx

Put this in your Nginx.conf or something that’s included.

ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;

# Diffie-Hellman parameter for DHE ciphersuites
ssl_dhparam /etc/nginx/dhparam.pem;

ssl_protocols TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

# HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
add_header Strict-Transport-Security max-age=15768000;

# OCSP Stapling
ssl_stapling on;
ssl_stapling_verify on;

## verify chain of trust of OCSP response using Root CA and Intermediate certs
# actual chain is in each vhost
resolver valid=86400;
resolver_timeout 10;

Vhost configuration

I’ll assume you already have a vhost set up and we’re just going to add the SSL configuration.

listen 443 ssl;
listen [::]:443 ssl;

ssl_certificate /etc/letsencrypt/live/;
ssl_certificate_key /etc/letsencrypt/live/;
ssl_trusted_certificate /etc/letsencrypt/live/;

if ($scheme = http) {
   return 301 https://$server_name$request_uri;

The result

To test your set up you can go to SSL Labs. You should be getting an A+.

Renewing a certificate

The letsencrypt-auto binary has a renew account which I use in a cron job. It will loop through all of your certificates and check if a renewal is pending.

I recommend you run this command every week to make sure all of your certificates renew in time.

sh /root/letsencrypt/letsencrypt-auto renew && service nginx reload >/var/log/renew.log