- Advertisement -


  • A registered domain name with valid A DNS records to point back to server public IP Address.
  • Nginx web server installed with SSL enabled and Virtual Hosts enabled (only for multiple domains or subdomains hosting).

Our Testing Environment Setup

Step 1: Install Nginx Web Server

1. On the first step, in case you don’t have Nginx daemon already installed, issue the below commands with root privileges in order to install Nginx webserver from Epel repositories:

Step 2: Download or Clone Free Let’s Encrypt SSL Certificate

2. The fastest method of installing Let’s Encrypt client on Linux systems in by cloning the packages from github repositories.

- Advertisement -

First, install git client on the system with the below command:

3. After git client has been installed, change directory to /opt path and pull Let’s Encrypt software by running the below commands:

Step 3: Generate a Free Let’s Encrypt SSL Certificate for Nginx

4. The process of obtaining a free SSL/TLS Certificate for Nginx will be done manually by using Let’s Encrypt Standalone plugin.

This method requires that port 80 must be free during the time Let’s Encrypt client validates the server’s identity and generates certificates.

So, if Nginx is already running, stop the daemon with the following command and run ss utility to confirm that port 80 is no longer in use in network stack.


5. Now it’s time to obtain a free SSL Certificate from Let’s Encrypt. Move to Let’s Encrypt installation directory, if you’re not already there, and run the letsencrypt-auto command with the certonly –standalone option and -d flag for each domain or subdomain you wish to generate a certificate as suggested in the below example.


6. After a series of packages and dependencies being installed on your machine, Let’s Encrypt will prompt you to enter your account which will be used for lost key recovery or urgent notifications.


7. Next you should agree the license terms by pressing Enter key.


8. Finally, if everything went as it should, a congratulation info message will be shown on your bash terminal. The message will also display when the certificate will expire.


Step 4: Install Let’s Encrypt SSL Certificate in Nginx

9. Now that you own a free SSL/TLS Certificate, it’s time to install it in Nginx webserver in order for your domain to use it.

All new SSL certificates are placed in /etc/letsencrypt/live/ under a directory named after your domain name. Use ls command to list the Certificate files issued for your domain and identify them.


10. To install the certificate files in Nginx and enable SSL, open /etc/nginx/nginx.conf file for editing and add the below statements after the last listen line from server block. Use the below illustration as guide.

Nginx SSL block excerpt:


Replace the domain name string for SSL certificates to match your own domain.

11. Finally, restart Nginx service and visit your domain via HTTPS Protocol at https://yourdomain. The page should load smooth, without any certificate error.

12. In order to verify the SSL/TLS certificate and its straightness visit the following link:



13. In case you get a notification that your server supports a weak DH key exchange and an overall rating of B grade, generate a new Diffie-Hellman cipher in /etc/nginx/ssl/ directory to protect your server against the Logjam attack by running the following commands.

In this example we’ve used a 4096 bit key, which actually takes a long time to generate and puts an extra overhead on your server and on SSL handshake.

In case there’s no explicit need to use a key this long and you’re not to paranoid, you should be safe with a 2048 bit key.

14. After DH key has been generated, open Nginx configuration file and add the below statements after ssl_ciphers line in order to add the DH key and rise the security level of your domain to an A+ grade.

Add following block excerpt to Nginx.conf:


15. Restart Nginx service to apply changes and retest your SSL certificate by clearing the previous result cache from the link mentioned above.


Step 5: Auto Renew Nginx Free Lets Encrypt SSL Certificates

16. Let’s Encrypt CA releases free SSL/TLS certificates valid for 90 days. Certificates can be manually renewed and applied before expiration using the webroot plugin, without stopping your web server, by issuing the below commands:


When running the above command make sure you replace the webroot-path to match your web server document root, specified by Nginx root statement.

17. In order to auto renew the certificate before it expires create this bash script from github erikaheidi in /usr/local/bin/ directory and add the below content (the script it’s slightly modified to reflect Nginx setting).

Add following lines to cert-renew file.

18. Replace the $webpath variable from the beginning of the script to match your Nginx document root. Make sure the script is executable and the bc calculator is installed on your system by issuing the following commands.

You can test the script against your domain by issuing the following command:


19. Finally, to run the certificate renewal process automatically, add a new cron job to execute the script every week in order update the certificate within 30 days before the expiration date.

Add the following line at the bottom of the file.

That’s all! Now Nginx server can deliver secure web content with a free SSL/TLS Let’s Encrypt certificate on your website.

- Advertisement -

There are no comments yet

  • Hello, guest