Install Let's Encrypt Certificates on Ubuntu for Nginx

Install Let's Encrypt Certificates on Ubuntu for Nginx

Marcell Simon
Marcell Simon

First you have to set the A Record for your domain.

Then to be sure, update your packages:

sudo apt update

Install certbot for older Ubuntu:

sudo add-apt-repository ppa:certbot/certbot
sudo apt install python-certbot-nginx -y

On Ubuntu 20.04:

sudo apt install certbot python3-certbot-nginx

Or on Amazon Linux 2

sudo wget -r --no-parent -A 'epel-release-*.rpm'
sudo rpm -Uvh*.rpm
sudo yum-config-manager --enable epel*
sudo yum install -y certbot python2-certbot-nginx

Add `server_name` tag to each nginx server.

server {
    location /lets {
    	return 200;

Reload nginx

sudo systemctl reload nginx

Add certicifates

sudo certbot --nginx -d

Refresh certificates if it didn't do it automatically

sudo certbot renew

Amazon Linux does not refresh the certificate automatically. To set it up, add a cron job.

export VISUAL=nano; crontab -e

and add a new line:

0 8 28 */2 * sudo certbot renew

This will regenerate the certificate every 2nd month on the 28th at 08:00.

Join the conversation.