## Rename to .subdomain.conf, copy to SWAG's /config/nginx/proxy-confs/, ## validate, reload. ## ## The subdomain has to exist before this does anything: add 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/hosting.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.rittershofer.org; 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; # 0 is no limit. Set a real one if strangers can post to this app; leave it # off when the only uploads are yours and can be large. client_max_body_size 0; # Guessing the password is already pointless if the app locks out after a # handful of wrong answers (see docs/password-protection.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. location ~ ^/login(/passkey)?$ { 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.