Setup Let's Encrypt with Nginx
When I migrated my VPS (with Ubuntu) to another host, I needed to set up Nginx again with Let's Encrypt, but I always forget exactly how to do it. This blog post describes in easy steps how to set up Nginx with auto-renewing Let's Encrypt SSL certificates.
Setting up Nginx
Setting up Nginx is super easy on Ubuntu. Run the following commands on your VPS.
sudo apt update sudo apt install nginx
If you have a firewall (ufw) enabled, run the following command to allow HTTP (80) and HTTPS (443) through the firewall.
sudo ufw allow 'Nginx Full'
Installing Certbot
Certbot is also super easy. Run the following commands on your VPS.
sudo apt-get update sudo apt-get install software-properties-common sudo add-apt-repository universe sudo add-apt-repository ppa:certbot/certbot sudo apt-get update sudo apt-get install certbot python-certbot-nginx
Getting an SSL certificate from Let's Encrypt
Now that we installed Certbot, we can get a certificate from Let's Encrypt by running the following command.
sudo certbot --nginx -d example.com -d www.example.com
Auto-renew your certificates
To auto-renew the certificates you have installed, add the following command to your crontab (open by running crontab -e from the terminal):
0 * * * * sudo certbot renew