# HTTPS and Let's Encrypt: get a free certificate

> HTTPS is HTTP over TLS; a certificate proves the server owns the domain, and Let's Encrypt issues them for free through an automated check.

URL: https://levelrail.com/learn/domains-https/https-and-lets-encrypt/
Updated: 2026-11-27

To get HTTPS for free, point your domain at the server, open ports 80 and 443, and run [certbot](https://levelrail.com/learn/glossary/#certbot)) to request a certificate from [Let's Encrypt](https://levelrail.com/learn/glossary/#lets-encrypt)). The certificate lasts 90 days and certbot renews it automatically, so you only need to confirm that renewal works.

## How it works

HTTPS is ordinary HTTP carried inside a [TLS](https://levelrail.com/learn/glossary/#tls)) connection. When the browser connects, the server sends its certificate. The certificate says "this public key belongs to example.com" and is signed by a certificate authority (CA) that the browser already trusts. The browser checks the signature, the name, and the dates. If all is good, both sides agree on keys and everything after that is encrypted. Anyone on the network between them sees only scrambled bytes.

The CA needs proof that you control the domain before it signs. Let's Encrypt does this with the ACME protocol. With the HTTP-01 challenge, the CA gives your client a token, your client serves it at `http://example.com/.well-known/acme-challenge/...` on port 80, and the CA fetches it from the internet. If the fetch works, you control that name. The CA then signs the certificate. For wildcards or servers that are not reachable from the internet, the DNS-01 challenge proves control with a DNS TXT record instead.

Certificates last 90 days on purpose, so a stolen key stops being useful soon and renewal is automated. Certbot installs a systemd timer (or cron job) that renews certificates that are close to expiring.

## Step 1: Install certbot

```bash
sudo apt install certbot
```

What you should see: apt installs the package and its dependencies. Check with `certbot --version`, which prints a version number.

## Step 2: Get a certificate

With nothing listening on port 80:

```bash
sudo certbot certonly --standalone -d example.com -d www.example.com
```

`certonly` gets the certificate but does not edit any web server config. `--standalone` makes certbot run a small temporary web server on port 80 for the check. Each `-d` adds a name to the certificate. Certbot may ask for an email address (for expiry notices) and to agree to the terms. What you should see: a message that the certificate was received, and file paths under `/etc/letsencrypt/live/example.com/`. Point your web server at `fullchain.pem` (certificate plus chain) and `privkey.pem`.

To practice without using real issuance, add `--staging` to the command. It uses Let's Encrypt's staging environment, whose certificates browsers do not trust, and whose limits are more generous for testing.

## Step 3: Test renewal

```bash
sudo certbot renew --dry-run
```

What you should see: a simulated renewal for each certificate that ends with a success message. This is the check that matters most, because failures here are the ones that bite you in 60 days.

## Check it worked

```bash
sudo certbot certificates
```

You should see the certificate name, its domains, an expiry date about 90 days out, and the file paths. Then, after your web server uses the certificate:

```bash
curl -I https://example.com
```

What you should see: an HTTP status line with no certificate error. To check the renewal timer exists, run `systemctl list-timers` and look for `certbot`.

## Edge cases and gotchas

- **Rate limits exist.** Repeated failed attempts can lock you out for a while. Test with `--staging` first and do not loop retries.
- **Port 80 must be reachable from the internet.** A cloud firewall or security group in front of the server blocks it even when ufw allows it. Open it in both places.
- **Standalone renewals can fail later.** Once nginx or another service holds port 80, `--standalone` cannot bind. Switch to the webroot or nginx plugin, or use a renewal hook that stops and starts the service.
- **AAAA records are tested too.** If the name has an AAAA record, the CA may connect over IPv6. A wrong or dead AAAA makes validation fail even though IPv4 works.
- **A redirect to HTTPS must not block the challenge.** Redirecting `/.well-known/acme-challenge/` incorrectly, or a CDN that proxies port 80, can break the check. Tokens are plain HTTP files.
- **The system clock matters.** A server with a badly wrong clock sees fresh certificates as not yet valid or already expired. Keep time synced (see the systemd timesyncd or chrony docs).
- **Certificates are per name set.** A certificate for `example.com` does not cover `www.example.com` unless you list it, and a wildcard needs DNS-01.
- **A proxy that ends TLS changes the picture.** Behind a CDN, the visitor's certificate is the CDN's, and your origin certificate is a separate matter.

## Troubleshooting

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| `Could not bind TCP port 80 because it is already in use by another process on this system` | A web server holds port 80 | Stop it briefly, or use the webroot or nginx plugin |
| `Timeout during connect (likely firewall problem)` | Port 80 is not reachable from the internet | Open port 80 in ufw and in the cloud firewall |
| Validation fails with `NXDOMAIN` | The name does not exist in DNS | Add the record, wait for it to appear in `dig` |
| Validation reaches the wrong server | A or AAAA points elsewhere | Fix the records, check both with `dig` |
| Browser shows `NET::ERR_CERT_DATE_INVALID` | Certificate expired, or clock is wrong | Renew, and check the clock with `timedatectl` |
| Browser shows `NET::ERR_CERT_COMMON_NAME_INVALID` | Certificate does not list the name you typed | Reissue with `-d` for every name you serve |
| Renewal dry run fails | Port 80 busy, or config changed since issuing | Read `/var/log/letsencrypt/letsencrypt.log` and fix the cause |
| Rate limit message | Too many recent attempts | Wait, and test with `--staging` |
| `certbot: command not found` | Certbot is not installed or not on the path | Install it with apt, or use the snap method on the certbot site |

## Real-world scenario

Dan has a site on a new VPS and wants HTTPS before launch. He checks `dig +short example.com A` and `dig +short www.example.com A`: both show 203.0.113.10. He stops nginx for a moment because it holds port 80, and tries a practice run first:

```bash
sudo certbot certonly --standalone --staging -d example.com -d www.example.com
```

The staging run succeeds, so DNS and the firewall are fine. He runs the real command without `--staging`, points nginx at `fullchain.pem` and `privkey.pem`, and starts nginx. Then he runs `sudo certbot renew --dry-run` and it fails because nginx owns port 80. He switches to the nginx plugin (`sudo certbot --nginx`) so renewal does not need the port. The proxy side is in [nginx reverse proxy with certbot](https://levelrail.com/learn/domains-https/nginx-reverse-proxy-with-certbot/)), and the routine for renewals is [renew Let's Encrypt certificates](https://levelrail.com/learn/domains-https/renew-lets-encrypt-certificates/)).

## Quick reference

| Task | Command |
| --- | --- |
| Install | `sudo apt install certbot` |
| Practice issue | add `--staging` |
| Issue standalone | `sudo certbot certonly --standalone -d example.com -d www.example.com` |
| List certificates | `sudo certbot certificates` |
| Test renewal | `sudo certbot renew --dry-run` |
| Files | `/etc/letsencrypt/live/example.com/fullchain.pem` and `privkey.pem` |

## Security and safety notes

- Keep `privkey.pem` private. Never commit it to git or paste it into a chat.
- Do not delete `/etc/letsencrypt`: it holds your account and renewal settings.

## Related lessons

- [Point a domain at your server](https://levelrail.com/learn/domains-https/point-a-domain-at-your-server/)): the step before this one
- [Inspect a TLS certificate with OpenSSL](https://levelrail.com/learn/domains-https/inspect-a-tls-certificate-with-openssl/)): read what you were issued
- [Renew Let's Encrypt certificates](https://levelrail.com/learn/domains-https/renew-lets-encrypt-certificates/)): keep it working after 90 days
- [Automatic HTTPS with Caddy](https://levelrail.com/learn/domains-https/automatic-https-with-caddy/)): skip certbot entirely

## Next

Make one name the standard with [redirect www to the bare domain](https://levelrail.com/learn/domains-https/redirect-www-to-the-bare-domain/)).

## Frequently asked questions

### How long does a Let's Encrypt certificate last?

90 days. Tools like certbot and most platforms renew them automatically well before they expire.

### Why did issuing fail?

The usual causes are a domain that does not yet point at the server, port 80 blocked by a firewall, or another program already using port 80.

### Do I need to buy a certificate to avoid browser warnings?

No. Let's Encrypt certificates are trusted by browsers and are free. Paid certificates mainly add support or validation levels, not stronger encryption.

### Can I get a certificate for a server that has no public IP?

Not with the HTTP-01 check, which needs the internet to reach port 80. Use the DNS-01 check, which proves control through a DNS record instead.


## Sources

- [Let's Encrypt, how it works](https://letsencrypt.org/how-it-works/)
- [Certbot instructions](https://certbot.eff.org/instructions)
