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 A record for the domain and one for www, both pointing at the server’s IPv4 address. If you also add AAAA (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.com with 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:

Server
$ dig +short example.com www.example.com203.0.113.10203.0.113.10
Output hidden (2 lines)

Step 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:

Server
$ sudo mkdir -p /var/www/example.com
Server
$ echo '<h1>example.com works</h1>' | sudo tee /var/www/example.com/index.html<h1>example.com works</h1>
Output hidden (1 line)

Write the server block (or create the file with sudo nano and paste the part between the EOF lines):

Server
$ 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

Turn it on, test, and reload:

Server
$ sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Server
$ sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
Output hidden (2 lines)
Server
$ sudo systemctl reload nginx
Server
$ curl http://example.com<h1>example.com works</h1>
Output hidden (1 line)

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:

Server
$ 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.
Output hidden (23 lines)
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.

Server
$ certbot --versioncertbot 4.0.0
Output hidden (1 line)

Step 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):

Server
$ 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- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Output hidden (39 lines)
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:

Server
$ 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: bytes
Output hidden (9 lines)

Plain HTTP now sends visitors to HTTPS:

Server
$ 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/
Output hidden (7 lines)

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):

Server
$ 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 GMT
Output hidden (4 lines)

Every certificate certbot manages, with the days left:

Server
$ 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- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Output hidden (12 lines)

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

Server
$ 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    }
Output hidden (34 lines)
  • 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 answers 404 to any other name.
  • ipv6only=on is on the [::]:443 line. 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 … 443 lines in the other order, [::]:443 first. Nothing else differs.
  • Edit this file as you would any other: test with sudo nginx -t, then sudo 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:

Server
$ 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.
Output hidden (5 lines)
Server
$ sudo grep renew_before_expiry /etc/letsencrypt/renewal/example.com.conf# renew_before_expiry = 30 days
Output hidden (1 line)

Test 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:

Server
$ 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)- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Output hidden (12 lines)

“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:

Server
$ sudo ufw delete allow 'Nginx Full'Rule deletedRule deleted (v6)
Output hidden (2 lines)
Server
$ sudo ufw allow 'Nginx HTTPS'Rule addedRule added (v6)
Output hidden (2 lines)

The site still loaded over HTTPS, but the renewal failed:

Server
$ 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.
Output hidden (26 lines)

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:

Server
$ sudo ufw allow 'Nginx Full'Rule addedRule added (v6)
Output hidden (2 lines)
Server
$ sudo ufw delete allow 'Nginx HTTPS'Rule deletedRule deleted (v6)
Output hidden (2 lines)
Server
$ sudo certbot renew --dry-run[… 7 lines not shown …]- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Congratulations, all simulated renewals succeeded:  /etc/letsencrypt/live/example.com/fullchain.pem (success)- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Output hidden (5 lines)

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:

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.
Output hidden (24 lines)

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:

Server
$ 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 failed
Output hidden (2 lines)

Put the plain port-80 block back (the same one as in step 2), then test and reload:

Server
$ 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
Server
$ sudo nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
Output hidden (2 lines)
Server
$ sudo systemctl reload nginx

What 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:

WhatUbuntu 26.04Ubuntu 24.04
SystemUbuntu 26.04.1 LTS7.0.0-30-genericUbuntu 24.04.4 LTS6.8.0-138-generic
nginx1.28.3-2ubuntu1.121.24.0-2ubuntu7.19
certbot4.0.0-42.9.0-1
python3-certbot-nginx4.0.0-32.9.0-1
python3-acme4.0.0-22.9.0-1
ufw0.36.2-9build10.36.2-6
Certbot from Ubuntu’s archive4.0.0 (packages added: 10)2.9.0 (packages added: 9)
The email promptEnter email address or hit Enter to skip.Enter email address (used for urgent renewal and security notices)
openssl x509 subject and issuer linessubject=CN=example.comsubject=CN = example.com
Order of the two listen … 443 lines certbot writes443 first, then [::]:443[::]:443 first, then 443
Redirect, renewal timer, 30-day window, failed renewal when port 80 is closedsame textsame text
testssl.sh grade and open ports from outsideA+; 22, 80, 443A+; 22, 80, 443 (adds a “no KEMs offered” note)
ProofRun log, 41 checks passedRun log, 41 checks passed