December 7, 2015

November 25, 2019

Let’s Encrypt, NGINX and Ubuntu

Let’s Encrypt has ./images/images/ Public Beta. Let's try to test it. I will show simple way how to configure Let's Encrypt for NGINX on Ubuntu. You can read more about installation and configuration at

Clone letsentrypt repository from github:

git clone

We need to stop NGINX.

sudo service nginx stop

Now let's install client (it will install all required dependencies via apt-get), run it and create certificates. At the moment plugin for NGINX is not installed by default (experimental) so we will generate only certificates.

cd letsencrypt
./images/letsencrypt-auto certonly

Enter your e-mail address.

Accept terms of service.

Enter domain.

You will see some important information:

 - If you lose your account credentials, you can recover through
   e-mails sent to E_MAIL ADDRESS.
 - Your account credentials have been saved in your Let's Encrypt
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Let's
   Encrypt so making regular backups of this folder is ideal.

 - Congratulations! Your certificate and chain have been saved at
   etc/letsencrypt/live/ Your cert will
   expire on 2016-03-02. To obtain a new version of the certificate in
   the future, simply run Let's Encrypt again.
 - If like Let's Encrypt, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:
   Donating to EFF:          

Start NGINX.

sudo service nginx start

Now we need to configure NGINX. You can use Mozilla SSL Configuration Generator. Here is the most important part of my NGINX configuration:

server {
listen 80;
return 301 https://$server_name$request_uri;
server {
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/;
ssl_certificate_key /etc/letsencrypt/live/;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
# openssl dhparam -out dhparam.pem 2048
ssl_dhparam /etc/nginx/dhparam.pem;
ssl_protocols TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security max-age=15768000;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/letsencrypt/live/;
# because it's not related to Let's Encrypt

First part is only to redirect from HTTP to HTTPS. Second part is related to SSL configuration. As you can see all certificates exist in /etc/letsencrypt/live/YOUR_DOMAIN. We need to create dhparap.pem file. You can read more about it here and here. Openssl command above ssl_dhparam allows you to generate this file.

That's all. Reload NGINX to load new configuration.

sudo service nginx reload

My blog uses Let's Encrypt so you can see how it works. ;-)

Let me know if something doesn't work!

© 2020 Przemysław Kołodziejczyk