Files
jobboard/deploy/server/swag/app.subdomain.conf
T

72 lines
3.1 KiB
Plaintext

## Rename to <app>.subdomain.conf, copy to SWAG's /config/nginx/proxy-confs/,
## validate, reload.
##
## The subdomain has to exist before this does anything: add <app> to SWAG's
## SUBDOMAINS (or run it with a wildcard cert) and point the DNS record at the
## same address as the rest of the stack. See docs/Install Server.md.
## Per-IP throttle for the login endpoints, if the app has a password. Declared
## here at `http` scope — SWAG includes proxy-confs outside any server block,
## which is what makes this legal in this file. 1 MB of zone holds about 16,000
## addresses. Delete both this and the `location` below if there is no login.
limit_req_zone $binary_remote_addr zone=app_login:1m rate=6r/m;
server {
listen 443 ssl;
listen [::]:443 ssl;
server_name app.example.com;
include /config/nginx/ssl.conf;
# Put proxy defaults at server scope so location timeouts override them
# through inheritance, rather than duplicate directives from proxy.conf.
include /config/nginx/proxy.conf;
# nginx buffers a request body to disk before it hands it on, and the login
# takes one without a session, so no limit here lets anyone spool gigabytes.
# This is small. A route that takes a large upload gets its own
# `location = /path { client_max_body_size 0; proxy_request_buffering off;
# ... }` above `location /`, with the same proxy lines as below; streaming
# the body lets the app refuse a request without a session before nginx
# has stored any of it.
client_max_body_size 1m;
# Guessing the password is already pointless if the app locks out after a
# handful of wrong answers (see auth/README.md). This is the
# cheap half of the rest: attempts are slowed per address, at the proxy,
# before they reach the app at all. `burst=5 nodelay` lets a person who
# fat-fingers it a few times through immediately and then holds the rate.
# `/login/passkey/options` is open and writes a challenge row per call, so
# it is throttled with the two routes that check a credential.
location ~ ^/login(/passkey(/options)?)?$ {
limit_req zone=app_login burst=5 nodelay;
limit_req_status 429;
include /config/nginx/resolver.conf;
set $upstream_app app;
set $upstream_port 8787;
set $upstream_proto http;
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
}
location / {
include /config/nginx/resolver.conf;
set $upstream_app app;
set $upstream_port 8787;
set $upstream_proto http;
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
# Only if the app holds a WebSocket open. SWAG's proxy.conf already
# sets the Upgrade headers; what it also sets is a read timeout of a
# couple of minutes, which would close every open tab's socket on the
# minute and leave the browser reconnecting for no reason.
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}
}
## `listen 443 ssl` without `http2` is correct — `http2 on;` is set once at
## `http` scope in nginx.conf, and the `listen ... http2` parameter is
## deprecated in nginx 1.25 and later.