How to Secure Nginx with Let’s Encrypt SSL on RHEL / CentOS 7

Published on April 6, 2020 1 min read

In this tutorial, we are going to setup Let’s Encrypt SSL (free SSL) on CentOS / RHEL 7 server running Nginx webserver. Let’s get started:

Table of Contents

  1. Install Certbot Client
  2. Config Firewall
  3. Generate SSL Certificate
  4. Setup Auto-renewal
  5. Check Certificate Status
  6. Delete Certbot Certificate

Install Certbot Client

To install Certbot client, we’ve to add EPEL reposiory on our server:

sudo yum install epel-release

Now run this command to install Certbot with necessary packages:

sudo yum install httpd mod_ssl python-certbot-nginx

Confirm the installation by typing this command:

certbot --version

Config Firewall

If firewall is running on your server, you’ve to open HTTPS (443) port. If your system is running firewalld, run these commands:

# open 443 port
sudo firewall-cmd --zone=public --permanent --add-service=https
# reload firewall
sudo firewall-cmd --reload

If your system is running iptables, then run these commands:

sudo iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT

Generate SSL Certificate

We have the necessary modules to generate Let’s Encrypt SSL. To generate certificate for a single domain, run this command:

certbot --nginx -d

To generate SSL for multiple domains or subdomains, run this command:

certbot --nginx -d -d

Here, is the base domain.

You can also generate an SSL certificate by choosing a domain name. To do this, run this command to show all hosted domains:

certbot --nginx

Choose one option and run that command what you needed. After successful installation, you will see a message similar to this message:

 - Congratulations! Your certificate and chain have been saved at:
   Your key file has been saved at:
   Your cert will expire on 2019-10-24. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

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

Setup Auto-renewal

We know that Let’s Encrypt certificates are valid for 90 days. But we can renew the certificates very easily. Just run this command before the expiration date:

certbot renew

We can also setup a cronjob to renew automatically. Open the cronjob:

crontab -e

Then add this line:

0 0 * * 1 /usr/bin/certbot renew >> /var/log/sslrenew.log

Check Certificate Status

We have successfully installed Let’s Encrypt SSL. Now let’s check the status of the SSL certificate by visiting this URL:

Delete Certbot Certificate

To delete the certificate we have to run this command:

# to select domain name
certbot delete

# directly assign domain name
certbot delete --cert-name
The article is over. Thanks for reading. 🙂

Monthly Newsletter

One email a month, packed with the latest tutorials, delivered straight to your inbox.
We'll never send any spam or promotional emails.

Hey, I'm Md Obydullah. I build open-source projects and write on Laravel, Linux server, modern JavaScript and more on web development.