nginx

HTTPS with nginx and certbot, automatic or by hand.

nginx serves HTTPS. certbot gets the certificate from Let's Encrypt and renews it.

Automatic

sudo CERTBOT_EMAIL=admin@example.com bash install.sh zerodot.example.com --proxy nginx

CERTBOT_EMAIL is optional. Let's Encrypt sends expiry warnings to it.

certbot is an item in the Extras checklist. To skip it, add --no-certbot. With --ip (plain HTTP), the script does not run certbot.

The script does these steps:

  1. It installs nginx if nginx is missing.
  2. On Fedora and RHEL with SELinux enforcing, it asks to set httpd_can_network_connect.
  3. It opens ports 80 and 443 in ufw or firewalld, if the firewall is on.
  4. If nginx has a site for the domain, the script does not change it. It prints the settings that the site needs.
  5. If nginx -t fails, the script stops. It prints the site to add by hand.
  6. It writes the site file:
    • Debian and Ubuntu: /etc/nginx/sites-available/NAME.conf, with a link in /etc/nginx/sites-enabled/.
    • Fedora, RHEL and Arch: /etc/nginx/conf.d/NAME.conf.
  7. On Arch, nginx.conf does not load conf.d. The script asks to add the include line.
  8. It runs nginx -t. If nginx rejects the site, the script removes it.
  9. If certbot is on in the Extras checklist, it gets a certificate. certbot adds HTTPS to the site and a redirect from HTTP.
  10. It turns on the certbot renewal timer. Arch has no timer. The script adds zerodot-certbot-renew.timer.

If certbot fails (for example, the DNS record is not ready), the site works on HTTP. Sign-in needs HTTPS. Run certbot later:

sudo certbot --nginx -d zerodot.example.com

Manual

1. Install nginx and certbot

Debian and Ubuntu:

sudo apt install -y nginx certbot python3-certbot-nginx

Fedora:

sudo dnf install -y nginx certbot python3-certbot-nginx

RHEL, Rocky and Alma (certbot is in EPEL):

sudo dnf install -y nginx
sudo dnf install -y epel-release
sudo dnf install -y certbot python3-certbot-nginx

On RHEL (not Rocky or Alma), EPEL also needs the CodeReady Builder repository. See the EPEL guide.

Arch:

sudo pacman -S --needed nginx certbot certbot-nginx

Start nginx:

sudo systemctl enable --now nginx

2. Write the site

Use the site for your mode. Replace zerodot.example.com with your domain.

Docker mode. The app listens on 127.0.0.1:3000:

server {
    listen 80;
    listen [::]:80;
    server_name zerodot.example.com;

    client_max_body_size 100m;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header Connection "";
    # Live event streams must not wait for a full buffer.
    proxy_buffering off;
    proxy_read_timeout 1h;
    proxy_send_timeout 1h;

    location / {
        proxy_pass http://127.0.0.1:3000;
    }
}

Native mode. The API paths go to the API port (default 3003). All other paths go to the web port (default 3000). The ports of your install are in .zerodot-install.

server {
    listen 80;
    listen [::]:80;
    server_name zerodot.example.com;

    client_max_body_size 100m;
    proxy_http_version 1.1;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header Connection "";
    # Live event streams must not wait for a full buffer.
    proxy_buffering off;
    proxy_read_timeout 1h;
    proxy_send_timeout 1h;

    location ^~ /api/v1/ { proxy_pass http://127.0.0.1:3003; }
    location ^~ /api/auth/ { proxy_pass http://127.0.0.1:3003; }
    location ^~ /api/p/ { proxy_pass http://127.0.0.1:3003; }
    location ^~ /hooks/ { proxy_pass http://127.0.0.1:3003; }
    location ^~ /hooks-test/ { proxy_pass http://127.0.0.1:3003; }
    location ^~ /resume/ { proxy_pass http://127.0.0.1:3003; }
    location = /mcp { proxy_pass http://127.0.0.1:3003; }
    location ^~ /mcp/ { proxy_pass http://127.0.0.1:3003; }
    location ^~ /oauth2/ { proxy_pass http://127.0.0.1:3003; }

    location / {
        proxy_pass http://127.0.0.1:3000;
    }
}

What each setting does:

Setting Why
proxy_buffering off Live event streams (server-sent events) arrive at once.
proxy_read_timeout 1h A live event stream and a long webhook call stay open.
Host and X-Forwarded-* headers The app makes correct links and sees the IP address of the client.
client_max_body_size 100m File uploads up to 100 MB.
location ^~ /x/ A prefix. Same as /x/* in Caddy.
location = /mcp The path /mcp only.

3. Put the site in the correct folder

Debian and Ubuntu:

sudo nano /etc/nginx/sites-available/zerodot.conf
sudo ln -s /etc/nginx/sites-available/zerodot.conf /etc/nginx/sites-enabled/zerodot.conf

Fedora, RHEL, Rocky and Alma:

sudo nano /etc/nginx/conf.d/zerodot.conf

Arch:

  1. Write the site to /etc/nginx/conf.d/zerodot.conf.

  2. Open /etc/nginx/nginx.conf.

  3. Add this line in the http { } block:

    include /etc/nginx/conf.d/*.conf;
    

4. SELinux (Fedora, RHEL)

With SELinux enforcing, nginx cannot connect to the app. Set this boolean:

sudo setsebool -P httpd_can_network_connect 1

5. Test and reload

sudo nginx -t
sudo systemctl reload nginx

6. Open the firewall

With ufw:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

With firewalld:

sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --add-service=http --add-service=https

7. Get the certificate

sudo certbot --nginx -d zerodot.example.com --redirect -m admin@example.com --agree-tos

certbot adds the HTTPS part to the site.

8. Renew the certificate

Debian, Ubuntu, Fedora and RHEL: the certbot package has a timer. Turn it on:

sudo systemctl enable --now certbot.timer || sudo systemctl enable --now certbot-renew.timer

Arch has no timer. Add one:

sudo tee /etc/systemd/system/zerodot-certbot-renew.service >/dev/null <<'UNIT'
[Unit]
Description=Renew Let's Encrypt certificates

[Service]
Type=oneshot
ExecStart=/usr/bin/certbot renew --quiet --deploy-hook "systemctl reload nginx"
UNIT
sudo tee /etc/systemd/system/zerodot-certbot-renew.timer >/dev/null <<'UNIT'
[Unit]
Description=Renew certificates twice a day

[Timer]
OnCalendar=*-*-* 00,12:00:00
RandomizedDelaySec=1h
Persistent=true

[Install]
WantedBy=timers.target
UNIT
sudo systemctl daemon-reload
sudo systemctl enable --now zerodot-certbot-renew.timer

To test the renewal, run:

sudo certbot renew --dry-run

nginx has a site for the domain

The script does not change a site that exists. Add these settings to it by hand:

  • proxy_buffering off;
  • proxy_read_timeout 1h;
  • The Host, X-Forwarded-For and X-Forwarded-Proto headers.
  • The location blocks of your mode (see above).

With the Cloudflare proxy

If the DNS record has the orange cloud, see Cloudflare proxy.

Change this page on GitHub