Archived
98 lines
3.8 KiB
Markdown
98 lines
3.8 KiB
Markdown
# Nginx and Certbot integration
|
|
|
|
Nginx and Certbot are host infrastructure. They are intentionally not part of
|
|
the MEOVV Compose project. Compose publishes two HTTP upstreams on loopback:
|
|
|
|
- `127.0.0.1:8080` — MEOVV web application and product API
|
|
- `127.0.0.1:8081` — Stalwart discovery, OAuth, JMAP, and autoconfiguration
|
|
|
|
Mail protocols remain directly exposed by Stalwart on 25, 465, 587, and 993.
|
|
|
|
## Nginx
|
|
|
|
Copy `deploy/nginx/meovv-mail.conf.example` into the host's Nginx configuration,
|
|
replace `__MAIL_HOSTNAME__`, and change the two upstream ports if the bind values
|
|
in `.env` were customized. The routing split is required: sending every path to
|
|
MEOVV breaks OAuth/JMAP discovery, while sending every path to Stalwart hides the
|
|
MEOVV interface and REST API.
|
|
|
|
Validate and reload using the host's normal Nginx process. The example keeps
|
|
ACME HTTP-01 challenges under `/var/www/certbot`; it is compatible with Certbot's
|
|
webroot authenticator. If your existing Certbot integration uses the Nginx
|
|
authenticator, retain its generated challenge configuration instead.
|
|
|
|
The complete example references the final Certbot lineage and therefore should
|
|
be enabled only after that lineage exists. For a new hostname, obtain the first
|
|
certificate through your existing Nginx integration or a temporary port-80-only
|
|
challenge server, then enable the HTTPS server block.
|
|
|
|
Both Compose HTTP bindings default to `127.0.0.1`. Do not change them to a public
|
|
address. The Stalwart management/recovery endpoint must never be internet-facing.
|
|
|
|
## One certificate, two termination points
|
|
|
|
Nginx uses the Certbot certificate for HTTPS. Stalwart must use the same
|
|
certificate independently for SMTP submission and IMAP TLS. MEOVV mounts:
|
|
|
|
```text
|
|
secrets/tls/fullchain.pem -> /etc/stalwart/tls/fullchain.pem
|
|
secrets/tls/privkey.pem -> /etc/stalwart/tls/privkey.pem
|
|
```
|
|
|
|
After Certbot has issued the hostname certificate, make the initial controlled
|
|
copy (replace the two paths as needed):
|
|
|
|
```bash
|
|
sudo env \
|
|
MEOVV_BUNDLE_DIR=/opt/meovv-mail \
|
|
RENEWED_LINEAGE=/etc/letsencrypt/live/mail.example.com \
|
|
/opt/meovv-mail/deploy/certbot/deploy-hook.sh
|
|
```
|
|
|
|
Start the two containers and complete the MEOVV browser setup. Before removing
|
|
the temporary recovery account, register the mounted files with Stalwart:
|
|
|
|
```bash
|
|
docker compose up -d --build --remove-orphans
|
|
./mailctl configure-tls
|
|
./mailctl harden
|
|
```
|
|
|
|
`configure-tls` sends the recovery credential only to the loopback Stalwart
|
|
endpoint. It creates or updates a Stalwart `Certificate` object using file
|
|
references, selects it as `defaultCertificateId`, records the object id in
|
|
`secrets/tls/certificate_id`, and restarts Stalwart. If the Stalwart loopback
|
|
port was changed, pass a loopback URL explicitly:
|
|
|
|
```bash
|
|
./mailctl configure-tls --url http://127.0.0.1:9081/api
|
|
```
|
|
|
|
## Renewal hook
|
|
|
|
Install the hook in Certbot's renewal deploy-hook directory and set the bundle
|
|
location inside a small wrapper or Certbot service environment. For example:
|
|
|
|
```bash
|
|
sudo install -m 0755 \
|
|
/opt/meovv-mail/deploy/certbot/deploy-hook.sh \
|
|
/etc/letsencrypt/renewal-hooks/deploy/meovv-mail
|
|
```
|
|
|
|
The default hook expects the bundle at `/opt/meovv-mail`; set
|
|
`MEOVV_BUNDLE_DIR` if it lives elsewhere. Certbot supplies `RENEWED_LINEAGE`.
|
|
The hook copies only the certificate chain and private key, applies restrictive
|
|
permissions, and restarts Stalwart if it is running. Nginx renewal/reload remains
|
|
owned by your existing Certbot integration.
|
|
|
|
Test the entire renewal path before production:
|
|
|
|
```bash
|
|
sudo certbot renew --dry-run
|
|
openssl s_client -connect mail.example.com:465 -servername mail.example.com </dev/null
|
|
openssl s_client -connect mail.example.com:993 -servername mail.example.com </dev/null
|
|
```
|
|
|
|
Confirm that HTTPS, SMTP submission, and IMAP present the same current hostname
|
|
certificate after the dry run.
|