How to Setup Let’s Encrypt SSL with Nginx on CentOS 8
In this tutorial we will show you how to provide an encrypted HTTPS connection for our site on the Nginx web server using a free Let’s Encrypt SSL certificate. Necessary conditions:
- Domain name;
- CentOS 8 server with public IP that appears in the DNS A record of your domain name;
- Installed Nginx web server.
Installing and configuring snapd
It is better to use snapd to install and maintain Certbot. This way, it will always be updated, and automatic certificate renewal will be pre-configured. To install snapd, use the following commands:
Enable and start snapd.
Enable classic snap support.
Now reboot the system.
Check if the latest version of snapd is installed.
Installing the Certbot package
Before installing the Certbot package from snap, you must be sure that there is no other Certbot installed on the system.
Now, install Certbot from snap.
Run the following command to make sure that Certbot will start.
Automatic obtaining and installation of Let’s Encrypt SSL certificate on Nginx
We recommend configuring the Nginx virtual host by adding its configuration to the /etc/nginx/conf.d/ folder with the .conf extension. If this is not done, the HTTPS configuration for the domain will be added to the nginx.conf file. Execute the next command to begin the certificate acquisition process and follow the instructions.
After the process completes successfully, restart Nginx.
Redirect from HTTP to HTTPS is configured automatically. Now you can check the result by accessing the domain name in the address bar of your browser.
Automatic SSL certificate renewal
Automatic renewal of the SSL certificate is configured during the installation of Certbot from snap. You can check if the timer is running using this command:
If there is no output, try these locations:
cat /etc/cron.*/*
You can also run a test run of auto-renewing your certificates: