Install Let's Encrypt Certificates on Ubuntu or Amazon Linux for Nginx

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

On Ubuntu 22.04, they recommend installing it with snap:

sudo snap install core; sudo snap refresh core

sudo snap install --classic certbot

#link the command so you can run it with the certbot command
sudo ln -s /snap/bin/certbot /usr/bin/certbot 

Or on Amazon Linux 2

sudo wget -r --no-parent -A 'epel-release-*.rpm' http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/
sudo rpm -Uvh dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-*.rpm
sudo yum-config-manager --enable epel*
sudo yum install -y certbot python2-certbot-nginx

Add `server_name` tag to each nginx server.

server {
	server_name techread.me;
	
    location /lets {
    	return 200;
    }
}

Reload nginx

sudo systemctl reload nginx

Add certicifates

sudo certbot --nginx -d techread.me

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.