Reading time is 5 minute(s)
When I migrated my VPS (with Ubuntu) to an other host, I needed to setup Nginx again with Let's Encrypt but I always forget how to exactly do it. This blog post is aimed to describe in easy steps how to setup up Nginx with auto-renewing Let’s Encrypt SSL certificates.
Setting up Nginx is super easy on Ubuntu. Run the following commands on your VPS.
1sudo apt update sudo apt install nginx
If you have a firewall (ufw) enabled run the following command to enable HTTP (80) and HTTPS (443) to the firewall.
1sudo ufw allow 'Nginx Full'
Certbot is also super easy. Run the following commands on your VPS.
1sudo apt-get update2sudo apt-get install software-properties-common3 4sudo add-apt-repository universe5sudo add-apt-repository ppa:certbot/certbot6 7sudo apt-get update8sudo apt-get install certbot python-certbot-nginx
Now that we installed Certbot we can get a certificate from Let’s Encrypt by running the following command.
1sudo certbot --nginx -d example.com -d www.example.com
To auto-renew the certificates you have installed, add the following command to your crontab (open by running crontab -e from terminal)
10 \* \* \* \* sudo certbot renew