← back to Petitionyour

deploy/nginx-petitionyour.org.conf

95 lines

# petitionyour.org — Kamatera nginx vhost
#
# Modeled on the canonical /etc/nginx/sites-available/novasuede.com template.
#
# CRITICAL (2026-09-08 fleet HTTPS-000 incident — memory
# fleet-https-real-cause-ipbind-and-h2-coalescing-trap): the :443 server
# block MUST bind the public IP explicitly (`listen 45.61.58.125:443 ssl`),
# NOT the wildcard `listen 443`. A wildcard-only :443 silently misses the
# box's IP-bound default_server socket and the whole vhost goes HTTPS-000.
#
# The `listen [::]:443 ssl` (IPv6) line is commented out by default because
# novasuede.com's own live vhost has it commented with the note "tailscale
# holds v6 :443, no public IPv6" — Kamatera's tailscale interface can hold
# the IPv6 :443 socket, and a second vhost trying to bind it can fail
# `nginx -t` and freeze reload for the WHOLE box (every other vhost too —
# see memory kamatera-nginx-canary). Verify with `nginx -t` before enabling.
# :80 stays wildcard-bound (`listen 80;`) per the deploy smoke test, which
# curls 127.0.0.1/health by Host header.

# HTTP — ACME challenge + redirect to HTTPS
server {
    listen 80;
    listen 45.61.58.125:80;
    listen [::]:80;
    server_name petitionyour.org www.petitionyour.org;

    # Let's Encrypt ACME challenge
    location /.well-known/acme-challenge/ {
        root /var/www/html;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

# HTTPS — main config
server {
    listen 45.61.58.125:443 ssl;      # IP-BOUND — do not change to a bare `listen 443;`
    # listen [::]:443 ssl;            # commented — verify no tailscale v6:443 conflict before enabling (see note above)
    server_name petitionyour.org www.petitionyour.org;

    ssl_certificate /etc/letsencrypt/live/petitionyour.org/fullchain.pem;   # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/petitionyour.org/privkey.pem; # managed by Certbot
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;

    # Cloudflare real-IP restore (DW spec checklist — required on every CF-fronted vhost)
    set_real_ip_from 173.245.48.0/20;
    set_real_ip_from 103.21.244.0/22;
    set_real_ip_from 103.22.200.0/22;
    set_real_ip_from 103.31.4.0/22;
    set_real_ip_from 141.101.64.0/18;
    set_real_ip_from 108.162.192.0/18;
    set_real_ip_from 190.93.240.0/20;
    set_real_ip_from 188.114.96.0/20;
    set_real_ip_from 197.234.240.0/22;
    set_real_ip_from 198.41.128.0/17;
    set_real_ip_from 162.158.0.0/15;
    set_real_ip_from 104.16.0.0/13;
    set_real_ip_from 104.24.0.0/14;
    set_real_ip_from 172.64.0.0/13;
    set_real_ip_from 131.0.72.0/22;
    set_real_ip_from 2400:cb00::/32;
    set_real_ip_from 2606:4700::/32;
    set_real_ip_from 2803:f800::/32;
    set_real_ip_from 2405:b500::/32;
    set_real_ip_from 2405:8100::/32;
    set_real_ip_from 2a06:98c0::/29;
    set_real_ip_from 2c0f:f248::/32;
    real_ip_header CF-Connecting-IP;

    location /.well-known/acme-challenge/ {
        root /var/www/html;
    }

    location / {
        proxy_pass http://127.0.0.1:9730;
        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 Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_cache_bypass $http_upgrade;
    }
}