Nginx + Certbot on Ubuntu

This tutorial guides users on Ubuntu how to secure their websites with HTTPS. It demonstrates installing Certbot, which utilizes Let’s Encrypt, and configuring Nginx to automatically obtain and deploy SSL certificates. Following the steps, users can enable HTTPS and configure their firewall for secure connections.
generated by gemma3:4b

Automatically enable HTTPS on your website with EFF’s Certbot, deploying Let’s Encrypt certificates. This tutorial shows you how to install Certbot w/ Nginx on Ubuntu.

Table of Contents

To install certbot

Terminal window
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

Add/Update your server block

Make sure your Nginx server blocks match your domain+subdomains:

server_name example.com www.example.com;

If not, edit your Nginx config:

Terminal window
vi /etc/nginx/sites-available/default

And then restart your Nginx server:

Terminal window
sudo service nginx restart

Add certificate

Running this command will go through your Nginx config and add certificate locations to appropriate blocks:

Terminal window
sudo certbot --nginx

Allow HTTPS through the firewall:

Terminal window
sudo ufw allow 'Nginx Full'