Certbot free SSL certificate installation with Nginx

Nginx
1036
April 7, 2024
5 Minutes

It is important to use an SSL certificate to secure your website. These certificates are used to encrypt the exchange of information between your website visitors. Certbot is an open source tool powered by Let's Encrypt and is widely used to obtain free SSL certificates.

First of all, it is necessary to install Certbot. To install to run on Nginx;

sudo apt update
sudo apt install python3-certbot-nginx

The above commands will install Certbot and the required Certbot plugin for Nginx.

Certificate Installation

To obtain an SSL certificate using Certbot, it will be sufficient to run the command below.

sudo certbot --nginx

This command will automatically scan the domains in Nginx configuration files and provide action for all domains. During this process, it will ask you questions and in some cases, domains will be approved during installation.

Certificate Installation by Specifying Domain

Using Certbot, certificate installation can be done by specifying the domain.

sudo certbot --nginx -d example.com

You can install by changing your specified address instead of example.com. If you want to install more than one domain or at the same time with sub domains;

sudo certbot --nginx -d example.com -d www.example.com -d sub.example.com

We can specify domains by continuing our line with -d example.com as in the example above.

Creating Automatic Renewal Cron

Certificates created by Certbot are valid for 90 days. However, Certbot may automatically renew your certificates. A cron must be created for this renewal process.

To create a cron, you can open your crontab file using the crontab -e command and add the following line:

0 0 * * 1 certbot renew --quiet

You can access this page faster by scanning the QR code.