Short answer
Point your domain at the server, give it an Nginx server block with server_name, and keep port 80 open. Then run sudo apt install -y certbot python3-certbot-nginx and sudo certbot --nginx -d example.com -d www.example.com. Certbot gets the certificate, switches the site to HTTPS, redirects HTTP to it and renews it by itself.
Tested on Ubuntu 26.04 and 24.04, two separate runs. On 24.04? 2 sections differ, each step marked “On Ubuntu 24.04” right under it: Step 3: Install certbot, Step 4: Get the certificate. Everything that differed
Before you start
- An Ubuntu 26.04 or 24.04 server with a public IP address and a user with sudo (create one).
- A domain name. At your DNS provider, add an
Arecord for the domain and one forwww, both pointing at the server’s IPv4 address. If you also addAAAA(IPv6) records, Nginx must answer on that address too: Let’s Encrypt connects to it as well. - Nginx installed, with ufw allowing
Nginx Full(ports 80 and 443). A firewall in your provider’s panel must allow both ports too. - Replace
example.comwith your domain in every command.
Step 1: Check that the domain points at the server
Let’s Encrypt looks the name up and connects to that address, so both names must give your server’s address. A new record can take a few minutes to appear:
$ dig +short example.com www.example.com203.0.113.10203.0.113.10Step 2: Give the domain a server block
Certbot finds the site to change by its server_name. Without a block that names your domain, it gets the certificate but cannot install it. Create a folder and a page for the site:
$ sudo mkdir -p /var/www/example.com$ echo '<h1>example.com works</h1>' | sudo tee /var/www/example.com/index.html<h1>example.com works</h1>Write the server block (or create the file with sudo nano and paste the part between the EOF lines):
$ sudo tee /etc/nginx/sites-available/example.com > /dev/null <<'EOF'server { listen 80; listen [::]:80; server_name example.com www.example.com; root /var/www/example.com; index index.html;}EOFTurn it on, test, and reload:
$ sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/$ sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful$ sudo systemctl reload nginx$ curl http://example.com<h1>example.com works</h1>Open http://example.com in a browser on your computer too. If the server answers itself but the browser times out, a firewall is in the way, and certbot will fail for the same reason.
Step 3: Install certbot
Ubuntu’s own package is certbot 4.0 on 26.04 (2.9 on 24.04), kept patched by Ubuntu. python3-certbot-nginx is the plugin that edits Nginx for you:
$ sudo apt install -y certbot python3-certbot-nginx[… 62 lines not shown …]Setting up python3-pytz (2025.2-5)…Setting up python3-josepy (2.2.0-1)…Setting up python3-rfc3339 (2.0.1-2)…Setting up python3-acme (4.0.0-2)…Setting up python3-certbot (4.0.0-4)…Setting up certbot (4.0.0-4)…Created symlink '/etc/systemd/system/timers.target.wants/certbot.timer' → '/usr/lib/systemd/system/certbot.timer'.Setting up python3-certbot-nginx (4.0.0-3)…Processing triggers for man-db (2.13.1-1build1)… Scanning processes...Scanning linux images... Running kernel seems to be up-to-date. No services need to be restarted. No containers need to be restarted. No user sessions are running outdated binaries. No VM guests are running outdated hypervisor (qemu) binaries on this host.On Ubuntu 24.04
On 24.04 apt prints its older list ("The following NEW packages will be installed", nine of them) and certbot --version prints certbot 2.9.0.
$ certbot --versioncertbot 4.0.0Step 4: Get the certificate
Name every domain the certificate should cover with -d. Certbot asks three things the first time: an email for urgent notices, whether you accept the Terms of Service (Y), and whether to share your email with the EFF (your choice; N here):
$ sudo certbot --nginx -d example.com -d www.example.comSaving debug log to /var/log/letsencrypt/letsencrypt.logEnter email address or hit Enter to skip. (Enter 'c' to cancel): admin@example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Please read the Terms of Service at:https://letsencrypt.org/documents/LE-SA-v1.8-July-06-2026.pdfYou must agree in order to register with the ACME server. Do you agree?- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(Y)es/(N)o: Y - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Would you be willing, once your first certificate is successfully issued, toshare your email address with the Electronic Frontier Foundation, a foundingpartner of the Let's Encrypt project and the non-profit organization thatdevelops Certbot? We'd like to send you email about our work encrypting the web,EFF news, campaigns, and ways to support digital freedom.- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(Y)es/(N)o: NAccount registered.Requesting a certificate for example.com and www.example.com Successfully received certificate.Certificate is saved at: /etc/letsencrypt/live/example.com/fullchain.pemKey is saved at: /etc/letsencrypt/live/example.com/privkey.pemThis certificate expires on 2027-02-16.These files will be updated when the certificate renews.Certbot has set up a scheduled task to automatically renew this certificate in the background. Deploying certificateSuccessfully deployed certificate for example.com to /etc/nginx/sites-enabled/example.comSuccessfully deployed certificate for www.example.com to /etc/nginx/sites-enabled/example.comCongratulations! You have successfully enabled HTTPS on https://example.com and https://www.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -If you like Certbot, please consider supporting our work by: * Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate * Donating to EFF: https://eff.org/donate-le- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -On Ubuntu 24.04
Certbot 2.9.0 on 24.04 asks the same three things in other words. The first prompt reads Enter email address (used for urgent renewal and security notices), and the Terms of Service text is wrapped on different lines. Answer the same way: your email, Y, then N or Y for the EFF.
Certbot did not ask about a redirect: since version 2 it adds one by default. The certificate lasts 90 days; renewal (below) is already set up.
Step 5: Check that HTTPS works
curl refuses a certificate it does not trust, so a 200 here means the certificate is valid:
$ curl -I https://example.comHTTP/1.1 200 OKServer: nginx/1.28.3 (Ubuntu)Date: Wed, 18 Nov 2026 22:13:15 GMTContent-Type: text/htmlContent-Length: 34Last-Modified: Wed, 18 Nov 2026 22:11:44 GMTConnection: keep-aliveETag: "6afe22a0-22"Accept-Ranges: bytesPlain HTTP now sends visitors to HTTPS:
$ curl -I http://example.comHTTP/1.1 301 Moved PermanentlyServer: nginx/1.28.3 (Ubuntu)Date: Wed, 18 Nov 2026 22:13:20 GMTContent-Type: text/htmlContent-Length: 178Connection: keep-aliveLocation: https://example.com/Who issued the certificate, and for how long (on 24.04 the subject and issuer are printed with spaces around the =, as subject=CN = example.com):
$ echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -subject -issuer -datessubject=CN=example.comissuer=C=US, O=Let's Encrypt, CN=YE1notBefore=Nov 18 21:14:34 2026 GMTnotAfter=Feb 16 21:14:33 2027 GMTEvery certificate certbot manages, with the days left:
$ sudo certbot certificatesSaving debug log to /var/log/letsencrypt/letsencrypt.log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Found the following certs: Certificate Name: example.com Serial Number: <serial> Key Type: ECDSA Domains: example.com www.example.com Expiry Date: 2027-02-16 21:14:33+00:00 (VALID: 89 days) Certificate Path: /etc/letsencrypt/live/example.com/fullchain.pem Private Key Path: /etc/letsencrypt/live/example.com/privkey.pem- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -In a browser on your computer, https://example.com now shows the padlock, and http://example.com moves to it.
What certbot changed in your server block
$ cat /etc/nginx/sites-available/example.comserver { server_name example.com www.example.com; root /var/www/example.com; index index.html; listen 443 ssl; # managed by Certbot listen [::]:443 ssl ipv6only=on; # managed by Certbot ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot }server { if ($host = www.example.com) { return 301 https://$host$request_uri; } # managed by Certbot if ($host = example.com) { return 301 https://$host$request_uri; } # managed by Certbot listen 80; listen [::]:80; server_name example.com www.example.com; return 404; # managed by Certbot }- Your block now listens on 443 with
ssl, and has the certificate, the key and certbot’s TLS settings (options-ssl-nginx.conf). Each line ends in# managed by Certbot. - A new block on port 80 sends each name to HTTPS with
if ($host = …) { return 301 … }, and answers404to any other name. ipv6only=onis on the[::]:443line. Only one block per port may carry it, and certbot adds it only when no other block has it.- On 24.04 certbot writes the two
listen … 443lines in the other order,[::]:443first. Nothing else differs. - Edit this file as you would any other: test with
sudo nginx -t, thensudo systemctl reload nginx. Renewal replaces the certificate files, not these lines.
Renewal: already set up
The package turned on a systemd timer when it was installed. It runs certbot renew twice a day, at a random time, and certbot renews a certificate only when it has 30 days or less left:
$ systemctl list-timers certbot.timer --no-pagerNEXT LEFT LAST PASSED UNIT ACTIVATESThu 2026-11-19 10:23:15 UTC 12h - - certbot.timer certbot.service 1 timers listed.Pass --all to see loaded but inactive timers, too.$ sudo grep renew_before_expiry /etc/letsencrypt/renewal/example.com.conf# renew_before_expiry = 30 daysTest a renewal now without changing anything. --dry-run uses Let’s Encrypt’s test server, so it does not count against your limits and keeps your certificate:
$ sudo certbot renew --dry-runSaving debug log to /var/log/letsencrypt/letsencrypt.log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Processing /etc/letsencrypt/renewal/example.com.conf- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Account registered.Simulating renewal of an existing certificate for example.com and www.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Congratulations, all simulated renewals succeeded: /etc/letsencrypt/live/example.com/fullchain.pem (success)- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -“Timeout during connect (likely firewall problem)”
Once HTTPS works, closing port 80 looks safe: every visitor goes to 443 anyway. It is not. Let’s Encrypt checks your server on port 80 at every renewal. In the test, port 80 was closed and only 443 left open:
$ sudo ufw delete allow 'Nginx Full'Rule deletedRule deleted (v6)$ sudo ufw allow 'Nginx HTTPS'Rule addedRule added (v6)The site still loaded over HTTPS, but the renewal failed:
$ sudo certbot renew --dry-runSaving debug log to /var/log/letsencrypt/letsencrypt.log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Processing /etc/letsencrypt/renewal/example.com.conf- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Simulating renewal of an existing certificate for example.com and www.example.com Certbot failed to authenticate some domains (authenticator: nginx). The Certificate Authority reported these problems: Domain: example.com Type: connection Detail: 203.0.113.10: Fetching http://example.com/.well-known/acme-challenge/RR1g0DPport6IdOV1xSmoEZv-ppXypwtX8luzQMoDbI: Timeout during connect (likely firewall problem) Domain: www.example.com Type: connection Detail: 203.0.113.10: Fetching http://www.example.com/.well-known/acme-challenge/9L3PbdE8pPg5VwQ4zSDTTwB7YTmHh8oUJ6_vdjfXEOY: Timeout during connect (likely firewall problem) Hint: The Certificate Authority failed to verify the temporary nginx configuration changes made by Certbot. Ensure the listed domains point to this nginx server and that it is accessible from the internet. Failed to renew certificate example.com with error: Some challenges have failed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -All simulated renewals failed. The following certificates could not be renewed: /etc/letsencrypt/live/example.com/fullchain.pem (failure)- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -1 renew failure(s), 0 parse failure(s)Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.Nothing on the site shows it: the timer would fail twice a day, writing only to its log, until the certificate expired. Open port 80 again:
$ sudo ufw allow 'Nginx Full'Rule addedRule added (v6)$ sudo ufw delete allow 'Nginx HTTPS'Rule deletedRule deleted (v6)$ sudo certbot renew --dry-run[… 7 lines not shown …]- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Congratulations, all simulated renewals succeeded: /etc/letsencrypt/live/example.com/fullchain.pem (success)- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -The same error on the first certbot --nginx means the same thing: something between the internet and Nginx drops port 80. Check sudo ufw status, then your provider’s firewall. The error starts with the address Let’s Encrypt connected to: if it is not your server’s, fix the DNS record (step 1).
Remove the certificate
revoke tells Let’s Encrypt the certificate must no longer be trusted (do this if the key may have leaked). Certbot then offers to delete its files, and warns that a certificate still in use stops the web server:
$ sudo certbot revoke --cert-name example.comSaving debug log to /var/log/letsencrypt/letsencrypt.log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Would you like to delete the certificate(s) you just revoked, along with allearlier and later versions of the certificate?- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(Y)es (recommended)/(N)o: Y - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -The following certificate(s) are selected for deletion: * example.com WARNING: Before continuing, ensure that the listed certificates are not beingused by any installed server software (e.g. Apache, nginx, mail servers).Deleting a certificate that is still being used will cause the server softwareto stop working. See https://certbot.org/deleting-certs for information ondeleting certificates safely. Are you sure you want to delete the above certificate(s)?- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -(Y)es/(N)o: YDeleted all files relating to certificate example.com.Congratulations! You have successfully revoked the certificate that was located at /etc/letsencrypt/live/example.com/cert.pem.The warning is real: the server block still names the deleted files, so the config no longer passes its test. Nginx keeps running on the config it had loaded, but the next reload or reboot would take the site down:
$ sudo nginx -t2026/11/18 22:18:01 [emerg] 6650#6650: cannot load certificate "/etc/letsencrypt/live/example.com/fullchain.pem": BIO_new_file() failed (SSL: error:80000002:system library::No such file or directory:calling fopen(/etc/letsencrypt/live/example.com/fullchain.pem, r) error:10000080:BIO routines::no such file)nginx: configuration file /etc/nginx/nginx.conf test failedPut the plain port-80 block back (the same one as in step 2), then test and reload:
$ sudo tee /etc/nginx/sites-available/example.com > /dev/null <<'EOF'server { listen 80; listen [::]:80; server_name example.com www.example.com; root /var/www/example.com; index index.html;}EOF$ sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful$ sudo systemctl reload nginxWhat these steps changed on the server
Both runs recorded the server before the first step and after the last (see the Tested on box below). Ten packages were added on 26.04 and nine on 24.04 (certbot, its Python libraries and the Nginx plugin), no service was enabled by hand (the renewal timer comes with the package), and port 443 now listens on IPv4 and IPv6. 27 files were added in /etc: certbot’s settings and account keys, the certificate, options-ssl-nginx.conf, ssl-dhparams.pem, a logrotate file and the timer link. The disk holds about 12 MB more on 26.04 and 11 MB on 24.04.
A scan of the 1,000 most common TCP ports from a second server found 22 (SSH) and 80 open before, and 22, 80 and 443 after. Nothing else opened. testssl.sh 3.2.5, run against the new HTTPS site, gave grade A+ on both releases and offers TLS 1.2 and 1.3 only (SSLv2, SSLv3, TLS 1.0 and 1.1 are off). Its warnings are the same on both: no HSTS header, no DNS CAA record and no security headers, and it flags BREACH only because the test page is gzip-compressed. Those are things you may add later; this guide does not.
Ubuntu 26.04 vs 24.04: what changed
The steps are the same. The differences are certbot’s version and how a few lines are written:
| What | Ubuntu 26.04 | Ubuntu 24.04 |
|---|---|---|
| System | Ubuntu 26.04.1 LTS7.0.0-30-generic | Ubuntu 24.04.4 LTS6.8.0-138-generic |
| nginx | 1.28.3-2ubuntu1.12 | 1.24.0-2ubuntu7.19 |
| certbot | 4.0.0-4 | 2.9.0-1 |
| python3-certbot-nginx | 4.0.0-3 | 2.9.0-1 |
| python3-acme | 4.0.0-2 | 2.9.0-1 |
| ufw | 0.36.2-9build1 | 0.36.2-6 |
| Certbot from Ubuntu’s archive | 4.0.0 (packages added: 10) | 2.9.0 (packages added: 9) |
| The email prompt | Enter email address or hit Enter to skip. | Enter email address (used for urgent renewal and security notices) |
openssl x509 subject and issuer lines | subject=CN=example.com | subject=CN = example.com |
Order of the two listen … 443 lines certbot writes | 443 first, then [::]:443 | [::]:443 first, then 443 |
| Redirect, renewal timer, 30-day window, failed renewal when port 80 is closed | same text | same text |
| testssl.sh grade and open ports from outside | A+; 22, 80, 443 | A+; 22, 80, 443 (adds a “no KEMs offered” note) |
| Proof | Run log, 41 checks passed | Run log, 41 checks passed |
