Certbot DNS Challenge

I’ve been using Certbot for a while now to manage my SSL certificates, using the http challenge to validate my domain ownership, but the process is very tedious: I needed to stop the NGINX server in order to certbot start the http server for the HTTP challenge and I also needed to disable the proxy on Cloudflare.
Has you can see, this is a very cumbersome process, so I decided to use the DNS challenge instead. This way, I avoid a lot of manual steps.
In this post, I’ll show you how to use the DNS challenge with Cloudflare. I’ll assume that you already have a domain and that you already have a Cloudflare account, since I’ll not cover those steps. I ran this commands on a Ubuntu 20.04 and 22.04 server, as well as Debian 11.
First of all, install the necessary packages:
Run the following command generate the certificates:
Note: In the command, you need to successfully make the HTTP challenge.
When running with the --nginx
flag, it will automatically configure the NGINX server to use the certificates and add configuration for the domain. Since I personally prefer to manage the NGINX configuration myself, I’ll show you how to do it manually.
Add the following configuration to the NGINX server in /etc/nginx/conf.d/example.com.conf
.
Note: If you don’t run the certbot command with the flag
--nginx
, it will not generage theoptions-ssl-nginx.conf
and thessl_dhparam
.
Make sure you generate a Cloudflare API Token key and store it in a safe place. You’ll need it to renew the certificates.
Finally, run the certbort command using DNS challenge to generate the certificates and check if everything is working:
If the command runs successfully, it should tell you that the certificates were generated and that it is scheculed to renew them.