Using Certbot with Nginx
Overview
When using a reverse proxy as a HTTPS endpoint for services within your network, you will need to ensure that the certificates are valid. This document will walk you through how to use Certbot to generate and renew certificates for your Nginx reverse proxy.
Prerequisites
Nginx installed on Ubuntu 22.04
A domain managed by Cloudflare
A Cloudflare account
A Cloudflare API token
Installation
Install Certbot
Create a Cloudflare API Token
Log into your Cloudflare account
Go to the
My ProfilesectionClick on
API TokensClick on
Create TokenSelect
Edit Zone DNSSelect the domain you want to generate the certificate for
Click on
Continue to SummaryClick on
Create TokenCopy the token
Creating a certbox configuration file
Create a file called cloudflare.ini with the following content:
Save the file under ~/.secrets/certbot/cloudflare.ini
Common Commands
Generate a Certificate
List Certificates
Renew Certificates
Generate Certificate for new Niignx site
Order a new Certificate
Edit the Nginx Configuration
Now add the newly generated certificate to the Nginx configuration file.
under /etc/nginx/conf.d/my.domain.conf add the following lines: