Move the retired nginx and certbot into .deprecated
Nothing references nginx/ or certbot/ since the cutover to Caddy (daa2a46),
so they join quartz, hasura and autoheal in .deprecated/, with a README
entry on how to bring them back. The rollback steps in DEPLOYMENT.md §7 now
revert this commit and then the cutover. The host keeps ./certbot/conf (the
last certbot certificate, valid until 2027-01-20) and ./logs/nginx until the
rollback is no longer wanted; .gitignore still covers certbot/conf and
certbot/www for that reason.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,681 @@
|
||||
# =============================================================================
|
||||
# nginx_routes.conf.template — the PROXY ROUTE TABLE shared by production and
|
||||
# dev. Add a new proxied route HERE, once.
|
||||
#
|
||||
# WHY THIS FILE EXISTS
|
||||
# nginx.conf.template (production) and nginx_dev_common.conf.template (dev)
|
||||
# used to each carry their own copy of these ~25 locations, so every new
|
||||
# route was two edits and the copies could drift — which matters more than
|
||||
# usual here, because this table holds the admin auth gates (/sb/,
|
||||
# /radio/admin/), the /py/internal/ 404 and the /notes privacy denials. A
|
||||
# route that exists in one copy but not the other is a hole that only shows
|
||||
# up in the environment you were not testing.
|
||||
#
|
||||
# WHO INCLUDES IT
|
||||
# - nginx.conf.template, inside its :443 www server block.
|
||||
# - nginx_dev_common.conf.template, which is itself included by BOTH dev
|
||||
# server blocks — so in dev this file is pulled in twice. That is fine:
|
||||
# each inclusion lands in a different `server`, and everything below is
|
||||
# server-scoped.
|
||||
#
|
||||
# HOW IT IS RENDERED
|
||||
# nginx/entrypoint.sh runs the SAME envsubst allow-list over this file as
|
||||
# over the main templates and writes the result to
|
||||
# /etc/nginx/nginx_routes.conf, the path the `include` directives name. It
|
||||
# does so on every boot path, before the main config is chosen. A new
|
||||
# substituted variable used here must be added to ENVSUBST_VARS in the
|
||||
# entrypoint, or it reaches nginx unsubstituted.
|
||||
#
|
||||
# WHAT BELONGS HERE
|
||||
# The `set $upstream_*` variables and every reverse-proxied location that
|
||||
# behaves the same in production and dev, plus the admin-gate subrequest
|
||||
# they rely on. It must stay brace-balanced on its own (no enclosing
|
||||
# `server {`).
|
||||
#
|
||||
# WHAT DOES NOT, AND WHY
|
||||
# - add_header, in any location here. nginx's add_header inheritance is
|
||||
# all-or-nothing: a location with none of its own inherits the including
|
||||
# server block's set. Production's server block includes
|
||||
# security_headers.conf (HSTS etc.) and dev's deliberately does not, so
|
||||
# leaving these locations header-free is what lets the same text carry
|
||||
# security headers in production and none on localhost. Adding a single
|
||||
# add_header to a location below would silently drop production's
|
||||
# security headers from it.
|
||||
# - /uploads/ and /uploads/private/. They need add_header lines of their
|
||||
# own AND, in production only, security_headers.conf alongside them, so
|
||||
# for the reason above they cannot be shared. Each template has its copy;
|
||||
# keep the auth_request pair on /uploads/private/ identical in both.
|
||||
# - `location /`. Production serves the built SPA from disk, dev proxies to
|
||||
# the Vite dev server.
|
||||
# - $BACKEND_ENDPOINT/graphql. Production-only, with its own tighter
|
||||
# rate-limit zone; in dev GraphQL falls through to $BACKEND_ENDPOINT/
|
||||
# below. It lives in nginx.conf.template.
|
||||
# - Static asset caching, robots.txt, the ACME challenge and TLS: production
|
||||
# only, in nginx.conf.template.
|
||||
#
|
||||
# RATE LIMITS
|
||||
# The limit_req lines below name the zones `login`, `upload`, `api` and
|
||||
# `hotel_search`. A zone must be declared with limit_req_zone in the `http`
|
||||
# block of whichever config includes this file, or nginx refuses to load it
|
||||
# — so BOTH nginx.conf.template and nginx_dev.conf.template declare all
|
||||
# four (same rates; the reasoning is annotated in the production one). If
|
||||
# you use a new zone here, declare it in both.
|
||||
#
|
||||
# ORDER
|
||||
# Prefix locations are matched longest-first, so their order here is
|
||||
# cosmetic. REGEX locations (`~`, `~*`) are tried in file order and the
|
||||
# first match wins: keep the two /notes deny regexes ahead of the
|
||||
# /py/hotels one, and remember production's ACME regex location is declared
|
||||
# before this file is included.
|
||||
# =============================================================================
|
||||
set $upstream_backend http://$BACKEND_HOST:$BACKEND_PORT;
|
||||
set $upstream_icecast http://$ICECAST_HOST:$ICECAST_PORT;
|
||||
set $upstream_gitea http://$GITEA_HOST:$GITEA_PORT;
|
||||
set $upstream_silverbullet http://$SILVERBULLET_HOST:$SILVERBULLET_PORT;
|
||||
set $upstream_silverbullet_public http://$SILVERBULLET_PUBLIC_HOST:$SILVERBULLET_PUBLIC_PORT;
|
||||
set $upstream_python http://$PYTHON_HOST:$PYTHON_PORT;
|
||||
# The job tracker's container name is fixed in docker-compose.yml, so
|
||||
# it needs no variable (and no ENVSUBST_VARS entry).
|
||||
set $upstream_jobs http://jobs:8080;
|
||||
# Likewise the activity tracker's.
|
||||
set $upstream_tracker http://activity-tracker:8080;
|
||||
# And the USACO site's.
|
||||
set $upstream_usaco http://usaco:8080;
|
||||
# And the Dozzle log viewer's.
|
||||
set $upstream_dozzle http://dozzle:8080;
|
||||
# Garage: its website endpoint (where /uploads/ is served from; see the
|
||||
# /uploads/ location in nginx.conf.template and
|
||||
# nginx_dev_common.conf.template) and the garage-webui admin UI.
|
||||
set $upstream_garage_web http://garage:3902;
|
||||
set $upstream_garage_webui http://garage-webui:3909;
|
||||
# The receipt printer's server is the one upstream OFF this host: it
|
||||
# runs on stppi, which reaches the printer over the home LAN, and is
|
||||
# reached over Tailscale by IP (MagicDNS names don't resolve in this
|
||||
# container).
|
||||
set $upstream_receipt "http://${RECEIPT_WEB_UPSTREAM}";
|
||||
|
||||
# ---- Backend API -----------------------------------------------------
|
||||
# Two patterns repeat through every proxied location below:
|
||||
#
|
||||
# 1. THE PREFIX-STRIP REWRITE
|
||||
# rewrite ^<PREFIX>/(.*)$ /$1 break;
|
||||
# The public URL carries a prefix (/api, /radio, /gitea, /py) but the upstream service serves its routes from /. The
|
||||
# rewrite strips the prefix and `break` stops rewrite processing so
|
||||
# the request stays in this location and goes to proxy_pass with the
|
||||
# rewritten URI. (This is why proxy_pass here has no trailing path —
|
||||
# with a variable upstream, nginx would not do the strip for us.)
|
||||
# The bare `location <PREFIX>` blocks that 301 to `<PREFIX>/` exist
|
||||
# only so a user typing /gitea without the slash lands correctly.
|
||||
#
|
||||
# 2. THE FOUR FORWARDING HEADERS
|
||||
# Host preserve the browser's hostname so the app
|
||||
# builds correct absolute URLs and cookies.
|
||||
# X-Real-IP the true client IP (the upstream otherwise
|
||||
# sees only nginx's container IP).
|
||||
# X-Forwarded-For appends the client to any existing chain.
|
||||
# X-Forwarded-Proto tells the app the ORIGINAL request was
|
||||
# https even though this hop is plain http.
|
||||
# Without it the backend would issue
|
||||
# non-Secure cookies and http:// redirects,
|
||||
# breaking auth behind TLS termination.
|
||||
#
|
||||
# Ordering matters: nginx picks the longest matching prefix location,
|
||||
# so the specific /ws, /auth/login and /uploads blocks (and
|
||||
# production's /graphql block in nginx.conf.template) win over the
|
||||
# catch-all <PREFIX>/ block regardless of file order.
|
||||
location $BACKEND_ENDPOINT {
|
||||
return 301 $BACKEND_ENDPOINT/;
|
||||
}
|
||||
|
||||
# WebSocket endpoint (live chat / activity feed).
|
||||
# The three lines that make an upgrade work, and why each is needed:
|
||||
# proxy_http_version 1.1 - HTTP/1.0 has no Upgrade mechanism at all.
|
||||
# Upgrade $http_upgrade - hop-by-hop headers are NOT forwarded by
|
||||
# Connection "upgrade" default, so they must be re-set by hand.
|
||||
# Note the Connection value is hardcoded rather than using the usual
|
||||
# $connection_upgrade map: this location only ever serves websockets, so
|
||||
# there is no plain-HTTP case to fall back to.
|
||||
# Deliberately NOT rate limited — a websocket is one long-lived request
|
||||
# and a limit_req here would drop reconnect storms, not abuse.
|
||||
location $BACKEND_ENDPOINT/ws {
|
||||
rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_backend;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
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;
|
||||
}
|
||||
|
||||
location $BACKEND_ENDPOINT/auth/login {
|
||||
limit_req zone=login burst=3 nodelay;
|
||||
rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_backend;
|
||||
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;
|
||||
}
|
||||
|
||||
location $BACKEND_ENDPOINT/uploads {
|
||||
limit_req zone=upload burst=20 nodelay;
|
||||
rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_backend;
|
||||
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;
|
||||
}
|
||||
|
||||
# Catch-all for the REST API. In production GraphQL does NOT land here:
|
||||
# nginx.conf.template declares a longer $BACKEND_ENDPOINT/graphql
|
||||
# location with a tighter zone. In dev it does.
|
||||
location $BACKEND_ENDPOINT/ {
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_backend;
|
||||
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;
|
||||
}
|
||||
|
||||
location /radio {
|
||||
return 301 /radio/;
|
||||
}
|
||||
|
||||
# Dozzle: live view of every container's logs, including the `traffic`
|
||||
# container's JSON request-body log (see payload_log.conf). It reads
|
||||
# the Docker socket, so it sits behind the same admin `auth_request`
|
||||
# as /radio/admin/. No prefix-strip rewrite: DOZZLE_BASE=/dozzle makes
|
||||
# it serve under the prefix itself. Buffering is off and the read
|
||||
# timeout long because log tails stream over server-sent events.
|
||||
location = /dozzle {
|
||||
return 301 /dozzle/;
|
||||
}
|
||||
|
||||
location /dozzle/ {
|
||||
auth_request /internal/auth/admin-validate;
|
||||
error_page 401 403 = @auth_denied;
|
||||
proxy_pass $upstream_dozzle;
|
||||
proxy_http_version 1.1;
|
||||
proxy_buffering off;
|
||||
proxy_read_timeout 1h;
|
||||
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;
|
||||
}
|
||||
|
||||
# garage-webui: buckets, keys and a file browser for the Garage object
|
||||
# store. It holds Garage's admin token, so it sits behind the admin
|
||||
# `auth_request` like /dozzle/, and its own login is left unset (one
|
||||
# login, not two). No prefix-strip rewrite: BASE_PATH=/garage makes it
|
||||
# serve under the prefix itself. The body limit is lifted past the
|
||||
# server-wide 50M so videos can be uploaded through it, and request
|
||||
# buffering is off so a large upload streams through instead of
|
||||
# landing on nginx's disk first.
|
||||
location = /garage {
|
||||
return 301 /garage/;
|
||||
}
|
||||
|
||||
location /garage/ {
|
||||
auth_request /internal/auth/admin-validate;
|
||||
error_page 401 403 = @auth_denied;
|
||||
client_max_body_size 2G;
|
||||
proxy_request_buffering off;
|
||||
proxy_pass $upstream_garage_webui;
|
||||
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;
|
||||
}
|
||||
|
||||
# The icecast ADMIN UI (/radio/admin/*) is a full station-control
|
||||
# surface — kick sources, change metadata — protected only by the
|
||||
# icecast admin password, and it was reachable from the public
|
||||
# internet through this proxy. Put it behind the same admin
|
||||
# `auth_request` as /sb/ so an admin session cookie is
|
||||
# required before the request ever reaches icecast. Longest-prefix
|
||||
# matching means this wins over /radio/ below; listener traffic
|
||||
# (/radio/$ICECAST_MOUNT, /radio/status.xsl) is untouched.
|
||||
location /radio/admin/ {
|
||||
auth_request /internal/auth/admin-validate;
|
||||
error_page 401 403 = @auth_denied;
|
||||
rewrite ^/radio/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_icecast;
|
||||
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;
|
||||
}
|
||||
|
||||
location /radio/ {
|
||||
rewrite ^/radio/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_icecast;
|
||||
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;
|
||||
}
|
||||
|
||||
location /gitea {
|
||||
return 301 /gitea/;
|
||||
}
|
||||
|
||||
location /gitea/ {
|
||||
rewrite ^/gitea/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_gitea;
|
||||
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;
|
||||
}
|
||||
|
||||
# Gitea's history views and archives, behind the admin gate. A crawler
|
||||
# swarm (129k requests from 103k IPs over 2026-10-18/19, so per-IP rate
|
||||
# limits are useless) walks every file at every commit, and those pages
|
||||
# are the expensive ones: diffs, blame, tarballs nginx spools to disk.
|
||||
# 89% of its requests were these shapes; people browsing the code use
|
||||
# the branch views (src/branch/..., commits/branch/...), which stay
|
||||
# public, so the CV's repo links still work. Gitea's own
|
||||
# REQUIRE_SIGNIN_VIEW=expensive would also block src/branch, hence
|
||||
# doing it here. A regex location, so it wins over /gitea/ above.
|
||||
location ~ ^/gitea/[^/]+/[^/]+/((src|raw|blame|commits|media)/commit/|commit/|archive/|compare/) {
|
||||
auth_request /internal/auth/admin-validate;
|
||||
error_page 401 403 = @auth_denied;
|
||||
rewrite ^/gitea/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_gitea;
|
||||
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;
|
||||
}
|
||||
|
||||
location /notes {
|
||||
return 301 /notes/;
|
||||
}
|
||||
|
||||
# PUBLIC notes viewer: a second, read-only SilverBullet over the same
|
||||
# vault the /sb/ editor edits. No auth_request — this is the public
|
||||
# site. See the silverbullet-public service in docker-compose.yml.
|
||||
#
|
||||
# THE DENY BLOCKS BELOW ARE THE PRIVACY BOUNDARY, not decoration.
|
||||
# SB_SPACE_IGNORE only hides paths from the file LIST. Everything else
|
||||
# happily serves them (all verified against 2.11.0 with curl):
|
||||
# /notes/.fs/private/x.md raw file, straight off disk
|
||||
# /notes/private/x the page URL: the server pre-renders the
|
||||
# note's content into the HTML shell
|
||||
# /notes/.fs/.git/... the vault's whole git repo, i.e. every
|
||||
# version of every private note ever
|
||||
# and gitignore semantics mean `private/` in SB_SPACE_IGNORE hides a
|
||||
# private/ folder at ANY depth from the list, so the block must too.
|
||||
#
|
||||
# 1. private/ or templates/ as any path segment, page URL or /.fs/.
|
||||
# ~* so Private/ is caught; (/|$) so the folder itself matches.
|
||||
# 2. Any dot-segment below the first: .git, .obsidian, .env, ... The
|
||||
# first segment is exempt because that is where SilverBullet's own
|
||||
# endpoints live (/.fs, /.config, /.client, /.events ...). Nothing
|
||||
# the client legitimately loads has a dot-segment deeper than that.
|
||||
# nginx matches against the normalised URI (percent-decoded, `..`
|
||||
# resolved, slashes merged), so %2F, // or ../ tricks cannot slip past.
|
||||
# Keep the folder list in step with SB_SPACE_IGNORE on
|
||||
# silverbullet-public. 404 rather than 403 so the response does not
|
||||
# confirm a private path exists.
|
||||
location ~* ^/notes/(.*/)?(private|templates)(/|$) {
|
||||
return 404;
|
||||
}
|
||||
|
||||
location ~ ^/notes/.+/\. {
|
||||
return 404;
|
||||
}
|
||||
|
||||
# Revisions are read from the vault's own .git, i.e. the full history
|
||||
# of every file INCLUDING private/ and anything ever deleted.
|
||||
# SB_REVISIONS=disabled already turns this off upstream; this is the
|
||||
# second lock in case that env var is ever dropped. ^~ so no regex
|
||||
# location can take precedence.
|
||||
location ^~ /notes/.revisions {
|
||||
return 404;
|
||||
}
|
||||
|
||||
# Same as /sb/: deliberately NO prefix-strip rewrite. The app is told
|
||||
# its base path via SB_URL_PREFIX=/notes and builds its service worker
|
||||
# scope and asset URLs from it; strip the prefix and it loads blank.
|
||||
# Upgrade/Connection are for its live-update event stream.
|
||||
location /notes/ {
|
||||
proxy_pass $upstream_silverbullet_public;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
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;
|
||||
}
|
||||
|
||||
location /sb {
|
||||
return 301 /sb/;
|
||||
}
|
||||
|
||||
# SilverBullet: the admin-only EDITOR for the vault /notes/ publishes.
|
||||
# Deliberately NO prefix-strip rewrite, unlike every other proxied app
|
||||
# here. SilverBullet is a PWA told its own base path via SB_URL_PREFIX=/sb,
|
||||
# and its service worker scope and asset URLs are built from that. Strip
|
||||
# the prefix and the app loads a blank page with no error in the log.
|
||||
# Upgrade/Connection are for its sync websocket.
|
||||
location /sb/ {
|
||||
auth_request /internal/auth/admin-validate;
|
||||
error_page 401 403 = @auth_denied;
|
||||
proxy_pass $upstream_silverbullet;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
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;
|
||||
}
|
||||
|
||||
location /py {
|
||||
return 301 /py/;
|
||||
}
|
||||
|
||||
# /py/hotels/search[/stream] and /py/hotels/scan/stream: long-running NDJSON streams
|
||||
location ~ ^/py/hotels/(search|scan) {
|
||||
# Public, up-to-a-minute upstream call with a single search slot: keep it to a few per minute per IP
|
||||
limit_req zone=hotel_search burst=2 nodelay;
|
||||
proxy_read_timeout 300s;
|
||||
proxy_send_timeout 300s;
|
||||
# The stream variant sends NDJSON progress lines; pass them through as they arrive
|
||||
proxy_buffering off;
|
||||
proxy_cache off;
|
||||
gzip off;
|
||||
rewrite ^/py/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_python;
|
||||
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;
|
||||
}
|
||||
|
||||
# /py/internal/: routes the Go backend calls directly over app-network
|
||||
# (the rowing photo reader and the job posting reader, which spend a
|
||||
# paid Claude call and have no auth of their own). Never proxied. ^~ so no regex location can claim
|
||||
# the path first. The Python side also refuses anything carrying the
|
||||
# X-Real-IP / X-Forwarded-For headers set below, as a second layer.
|
||||
location ^~ /py/internal/ {
|
||||
return 404;
|
||||
}
|
||||
|
||||
location /py/ {
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
# Hotel search blocks for up to a few minutes while it calls Travelodge and TfL
|
||||
proxy_read_timeout 300s;
|
||||
proxy_send_timeout 300s;
|
||||
rewrite ^/py/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_python;
|
||||
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;
|
||||
}
|
||||
|
||||
# ---- Job tracker (/jobs/) ----
|
||||
# Its own container (the adamf/job-tracker repo), which serves its SPA
|
||||
# and its API from the same prefix. The prefix is NOT stripped: the
|
||||
# app is built to live at /jobs/. Gated like /sb/: everything under
|
||||
# /jobs/ needs the admin session, checked here by auth_request before
|
||||
# the app sees it (the app still checks the session itself too). Two
|
||||
# exceptions, below, that a session cookie can never reach. ^~ so no
|
||||
# regex location can claim a /jobs/ path.
|
||||
location = /jobs {
|
||||
return 301 /jobs/;
|
||||
}
|
||||
|
||||
location ^~ /jobs/ {
|
||||
auth_request /internal/auth/admin-validate;
|
||||
error_page 401 403 = @auth_denied;
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
# "Sync now" on the Settings page runs a whole email sync before
|
||||
# answering.
|
||||
proxy_read_timeout 300s;
|
||||
proxy_pass $upstream_jobs;
|
||||
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;
|
||||
}
|
||||
|
||||
# The capture API is called by the userscript from job sites' origins,
|
||||
# with the capture bearer token rather than cookies, so it cannot pass
|
||||
# the session gate; the app's CaptureTokenMiddleware guards it.
|
||||
location ^~ /jobs/api/capture {
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
proxy_pass $upstream_jobs;
|
||||
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;
|
||||
}
|
||||
|
||||
# The userscript itself: userscript managers fetch its @updateURL
|
||||
# without the session, and it holds no secrets (the token is entered
|
||||
# after install).
|
||||
location = /jobs/job-capture.user.js {
|
||||
proxy_pass $upstream_jobs;
|
||||
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;
|
||||
}
|
||||
|
||||
# ---- USACO practice log (/usaco/) ----
|
||||
# Its own container (the usaco repo's site/), shaped like /jobs/: SPA
|
||||
# and API under one prefix that is NOT stripped, and no
|
||||
# auth_request, because most of it is public and the app checks the
|
||||
# session itself for the admin's edits. Gitea's push webhook does not
|
||||
# come through here: it calls the container directly on the Docker
|
||||
# network. ^~ so no regex location can claim a /usaco/ path.
|
||||
location = /usaco {
|
||||
return 301 /usaco/;
|
||||
}
|
||||
|
||||
location ^~ /usaco/ {
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
# An admin edit commits and pushes to Gitea before answering.
|
||||
proxy_read_timeout 120s;
|
||||
proxy_pass $upstream_usaco;
|
||||
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;
|
||||
}
|
||||
|
||||
# ---- Activity tracker (/tracker/) ----
|
||||
# Its own container (the adamf/ccp repo): an ingest API for device
|
||||
# collectors, which send batches of events with a per-device bearer
|
||||
# key, plus a dashboard and setup page. Gated like /sb/: the pages
|
||||
# and their assets need the admin session, checked here by
|
||||
# auth_request (the app also checks it itself). Two exceptions,
|
||||
# below: the API, which collectors call with bearer keys and no
|
||||
# cookies (the app guards each route, by device key, admin session or
|
||||
# either), and the public /tracker.user.js. Unlike /jobs/ the prefix
|
||||
# IS stripped: the server serves /api/v1/... and /readyz from /.
|
||||
# Collectors must use the www host: the apex 301 would turn their
|
||||
# POSTs into GETs. Health Auto Export bodies can be several MB; the
|
||||
# server-wide 50M client_max_body_size covers them.
|
||||
location = /tracker {
|
||||
return 301 /tracker/;
|
||||
}
|
||||
|
||||
location ^~ /tracker/ {
|
||||
auth_request /internal/auth/admin-validate;
|
||||
error_page 401 403 = @auth_denied;
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
rewrite ^/tracker/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_tracker;
|
||||
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;
|
||||
}
|
||||
|
||||
location ^~ /tracker/api/v1/ {
|
||||
limit_req zone=api burst=20 nodelay;
|
||||
rewrite ^/tracker/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_tracker;
|
||||
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;
|
||||
}
|
||||
|
||||
location = /tracker/tracker.user.js {
|
||||
rewrite ^/tracker/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_tracker;
|
||||
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;
|
||||
}
|
||||
|
||||
# ---- Receipt printer (/receipt/) ----
|
||||
# The adamf/receipt_maker repo's `receipt serve`, running on stppi
|
||||
# (not in this stack: that machine reaches the printer on the home LAN). A page
|
||||
# for printing a note or an uploaded image, plus its API. Behind the
|
||||
# permission gate on `receipt`, so an account granted it in the admin
|
||||
# panel can print without being an admin; the prefix IS stripped. The
|
||||
# server trusts nothing without X-Receipt-Token, which only this proxy
|
||||
# adds (proxy_set_header replaces any copy the client sent), and is
|
||||
# told who is printing in X-Remote-User, likewise only set here. The
|
||||
# token is quoted so an unset one still renders a valid config. When
|
||||
# stppi is off or unreachable the connect fails fast and
|
||||
# @receipt_offline answers.
|
||||
location = /receipt {
|
||||
return 301 /receipt/;
|
||||
}
|
||||
|
||||
location ^~ /receipt/ {
|
||||
set $auth_permission receipt;
|
||||
auth_request /internal/auth/validate;
|
||||
auth_request_set $auth_user $upstream_http_x_auth_user;
|
||||
error_page 401 = @auth_denied;
|
||||
error_page 403 = @auth_forbidden;
|
||||
error_page 502 504 = @receipt_offline;
|
||||
limit_req zone=api burst=10 nodelay;
|
||||
# The server caps uploads at 16 MB; this leaves room for the
|
||||
# multipart framing around one.
|
||||
client_max_body_size 17m;
|
||||
rewrite ^/receipt/(.*)$ /$1 break;
|
||||
proxy_pass $upstream_receipt;
|
||||
proxy_connect_timeout 3s;
|
||||
# An image print (connect, dither, send) takes a few seconds; a
|
||||
# dead printer socket gives up after escpos's 60 s timeout.
|
||||
proxy_read_timeout 90s;
|
||||
proxy_set_header X-Receipt-Token "${RECEIPT_WEB_TOKEN}";
|
||||
proxy_set_header X-Remote-User $auth_user;
|
||||
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;
|
||||
}
|
||||
|
||||
location @receipt_offline {
|
||||
default_type text/plain;
|
||||
return 503 "The receipt printer machine is offline.\n";
|
||||
}
|
||||
|
||||
# Where the tracker used to be. The SPA routes were client-side, so
|
||||
# these only catch bookmarks and typed URLs. The userscript's old
|
||||
# @updateURL lands on the third, which is how installed copies find
|
||||
# version 2.0.0 and its new API base.
|
||||
location = /cv/jobs {
|
||||
return 301 /jobs/;
|
||||
}
|
||||
location = /cv/leads {
|
||||
return 301 /jobs/leads;
|
||||
}
|
||||
location = /job-capture.user.js {
|
||||
return 301 /jobs/job-capture.user.js;
|
||||
}
|
||||
|
||||
# ---- Admin gate (/sb/, /jobs/, /tracker/, /dozzle/, /garage/, /radio/admin/, /uploads/private/) ----
|
||||
# (/uploads/private/ is declared in the including template, not here;
|
||||
# it points at the two locations below by name.)
|
||||
# `auth_request` makes nginx fire a subrequest here before serving the
|
||||
# real one; a 2xx lets it through, 401/403 triggers error_page ->
|
||||
# @auth_denied -> redirect to the SPA login. This puts the Go backend's
|
||||
# session cookie in front of services that have no idea it exists.
|
||||
# internal; - unreachable from outside, subrequest only.
|
||||
# proxy_pass_request_body off + Content-Length ""
|
||||
# - the subrequest must not replay the
|
||||
# original body (it could be a 50MB
|
||||
# upload); clearing Content-Length stops
|
||||
# the backend waiting for a body that is
|
||||
# not coming.
|
||||
# Cookie $http_cookie - the whole point: forward the session
|
||||
# cookie so the backend can validate it.
|
||||
# client_max_body_size 0 - the subrequest is checked against THIS
|
||||
# location's limit using the original
|
||||
# request's Content-Length, so without it
|
||||
# a gated location with a higher limit
|
||||
# (/garage/, 2G) 413s inside the auth
|
||||
# check and the user sees a 500. Safe:
|
||||
# the location is internal and never
|
||||
# reads a body; the real limit is the
|
||||
# gated location's own.
|
||||
location = /internal/auth/admin-validate {
|
||||
internal;
|
||||
client_max_body_size 0;
|
||||
rewrite ^ /auth/validate-admin break;
|
||||
proxy_pass $upstream_backend;
|
||||
proxy_pass_request_body off;
|
||||
proxy_set_header Content-Length "";
|
||||
proxy_set_header Cookie $http_cookie;
|
||||
}
|
||||
|
||||
location @auth_denied {
|
||||
return 302 /admin/login?redirect=$request_uri;
|
||||
}
|
||||
|
||||
# ---- Permission gate (/receipt/) ----
|
||||
# The same auth_request mechanism as the admin gate above, but asking
|
||||
# GET /auth/validate/<key> whether the session holds one named
|
||||
# permission (services/permissions.go; admins hold them all). A gated
|
||||
# location sets $auth_permission and points auth_request here:
|
||||
#
|
||||
# set $auth_permission <key>;
|
||||
# auth_request /internal/auth/validate;
|
||||
# error_page 401 = @auth_denied;
|
||||
# error_page 403 = @auth_forbidden;
|
||||
#
|
||||
# The variable reaches the subrequest because nginx subrequests share
|
||||
# the parent request's variables, and `set` runs in the rewrite phase,
|
||||
# before auth_request's access phase. It must NOT also be given a
|
||||
# default at server level: a subrequest re-runs the server-level
|
||||
# rewrite phase, so that `set` would blank the shared value before
|
||||
# this location reads it. (A location that forgets to set it asks for
|
||||
# /auth/validate/, which matches no route: denied.) 401 (not signed in) goes to the
|
||||
# login page as before; 403 (signed in, not granted) goes to a page
|
||||
# that says so, since sending a signed-in user to log in again only
|
||||
# shows them "Already signed in". On success the backend returns the
|
||||
# username in X-Auth-User, which a location can forward with
|
||||
# auth_request_set (see /receipt/). The body/limit settings are the
|
||||
# admin-validate location's, for the same reasons.
|
||||
location = /internal/auth/validate {
|
||||
internal;
|
||||
client_max_body_size 0;
|
||||
rewrite ^ /auth/validate/$auth_permission break;
|
||||
proxy_pass $upstream_backend;
|
||||
proxy_pass_request_body off;
|
||||
proxy_set_header Content-Length "";
|
||||
proxy_set_header Cookie $http_cookie;
|
||||
}
|
||||
|
||||
location @auth_forbidden {
|
||||
return 302 /no-access?path=$request_uri;
|
||||
}
|
||||
Reference in New Issue
Block a user