Gate deploys on tests and share the nginx route table

Makefile: make check runs the backend, Python, Vue and compose checks
that previously lived only in local notes.

deploy.yaml: a test job runs the backend and Python suites in containers
on every push, and deploy needs it. Deploy also refuses to run if main
has moved past the tested commit. maintenance.yaml takes the env-apply
lock around its compose steps, as deploy already did.

nginx: the 24 proxied locations that production and dev both carried now
live once in nginx_routes.conf.template, rendered by the entrypoint on
every boot path. The effective config is unchanged for both.

Remove the root package.json and lockfile, which nothing referenced.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-12 14:39:19 +01:00
co-authored by Claude Opus 5.5
parent d3f722d077
commit b832dd68b4
12 changed files with 809 additions and 1841 deletions
+10 -3
View File
@@ -1,5 +1,6 @@
# =============================================================================
# nginx image — the public edge. Stock nginx plus two tools and three templates.
# nginx image — the public edge. Stock nginx plus two tools, three config
# templates and the two partials they include.
#
# BASE: nginx:1.27, pinned to a minor version. Official nginx images are
# multi-arch, so the same tag resolves to the arm64 build on the Raspberry Pi
@@ -19,9 +20,11 @@
#
# apt lists are deleted in the SAME RUN layer so they never end up in the image.
#
# NO nginx.conf IS COPIED IN. All three templates (plus the dev partial) are,
# NO nginx.conf IS COPIED IN. All three templates (plus the two partials) are,
# and entrypoint.sh picks one at container start. See nginx/entrypoint.sh for
# that decision.
# that decision. A new partial needs BOTH a COPY here and an envsubst render in
# the entrypoint, or nginx fails at start with "open() ... failed" on the
# include.
# =============================================================================
FROM nginx:1.27
RUN rm -rf /etc/nginx/html/* && \
@@ -34,6 +37,10 @@ COPY nginx_dev.conf.template /etc/nginx/nginx_dev.conf.template
# (same envsubst allow-list) to /etc/nginx/nginx_dev_common.conf, which is the
# path both `include` directives in nginx_dev.conf.template point at.
COPY nginx_dev_common.conf.template /etc/nginx/nginx_dev_common.conf.template
# The proxy route table shared by production and dev. entrypoint.sh renders it
# (same envsubst allow-list) to /etc/nginx/nginx_routes.conf, the path
# nginx.conf.template and nginx_dev_common.conf.template both `include`.
COPY nginx_routes.conf.template /etc/nginx/nginx_routes.conf.template
# Static security-header include, referenced from nginx.conf.template (and
# any location that sets its own add_header). Not templated — no envsubst.
COPY security_headers.conf /etc/nginx/security_headers.conf
+50 -7
View File
@@ -6,8 +6,11 @@
# WHAT IT DOES
# nginx.conf is not shipped in the image. Instead three *templates* are baked
# in (see nginx/Dockerfile) and this script renders exactly one of them to
# /etc/nginx/nginx.conf before starting nginx in the foreground. In dev it
# also renders the shared server-block partial the dev template includes.
# /etc/nginx/nginx.conf before starting nginx in the foreground. It also
# renders the PARTIALS those templates `include`: the proxy route table
# shared by production and dev (nginx_routes.conf, every boot path) and, in
# dev only, the body shared by the two dev server blocks
# (nginx_dev_common.conf). See RENDERED FILES below.
# After nginx starts, a background watcher handles certificates appearing or
# being renewed — see CERTIFICATE WATCHER at the bottom of this file.
#
@@ -47,6 +50,19 @@
# Step (c) IS automatic now. A first deploy on a new domain no longer needs a
# manual `docker compose restart nginx`; a restart remains a valid fallback.
#
# RENDERED FILES (template in the image -> path nginx reads)
# nginx.conf.template | nginx_dev.conf.template | nginx_setup.conf.template
# -> /etc/nginx/nginx.conf (one of three)
# nginx_routes.conf.template -> /etc/nginx/nginx_routes.conf
# The reverse-proxy locations common to production and dev. Included
# by nginx.conf.template directly and by nginx_dev_common.conf. This is
# where a new proxied route goes.
# nginx_dev_common.conf.template -> /etc/nginx/nginx_dev_common.conf
# Dev only: included by both server blocks of nginx_dev.conf.template.
# The `include` directives name those rendered paths literally, so a partial
# must be written BEFORE anything runs nginx (or `nginx -t`) against a config
# that includes it.
#
# THE envsubst TEMPLATING PATTERN
# The templates are plain nginx configs containing $VARIABLES. Two different
# kinds of $VAR live in the same file:
@@ -93,10 +109,27 @@ export SILVERBULLET_PUBLIC_HOST="${SILVERBULLET_PUBLIC_HOST:-silverbullet-public
export SILVERBULLET_PUBLIC_PORT="${SILVERBULLET_PUBLIC_PORT:-3000}"
# The envsubst allow-list, defined once and reused by both full-config branches
# so the two lists cannot drift apart. It MUST stay single-quoted here and be
# passed as "$ENVSUBST_VARS" (one argument) below.
# and by every partial, so the lists cannot drift apart. It MUST stay
# single-quoted here and be passed as "$ENVSUBST_VARS" (one argument) below.
ENVSUBST_VARS='${DOMAIN} ${BACKEND_HOST} ${BACKEND_PORT} ${BACKEND_ENDPOINT} ${ICECAST_HOST} ${ICECAST_PORT} ${GITEA_HOST} ${GITEA_PORT} ${SILVERBULLET_HOST} ${SILVERBULLET_PORT} ${SILVERBULLET_PUBLIC_HOST} ${SILVERBULLET_PUBLIC_PORT} ${PYTHON_HOST} ${PYTHON_PORT}'
# Render the shared proxy route table. Done ONCE, here, ahead of the three-way
# decision, rather than inside each branch:
# - dev and production both include it, so both need it before nginx starts;
# - the setup branch does not include it, but the certificate watcher at the
# bottom of this file later switches setup -> production by validating a
# candidate production config with `nginx -t`, and that candidate includes
# this path. Having it already on disk means the watcher has nothing extra
# to render and no ordering to get wrong.
# It is safe to write straight to the live path (no temp file + validate, as
# the watcher does for nginx.conf): this runs before nginx has started, and
# its content depends only on the image's template and the container's
# environment, neither of which can change while the container lives — so
# there is never a newer version to swap in under a running nginx.
envsubst "$ENVSUBST_VARS" \
</etc/nginx/nginx_routes.conf.template \
>/etc/nginx/nginx_routes.conf
# Check if DEV_MODE
if [ "$DEV_MODE" = "true" ]; then
echo "Dev mode. Generating self-signed certificate for HTTPS."
@@ -112,7 +145,8 @@ if [ "$DEV_MODE" = "true" ]; then
fi
# In dev mode, so use nginx_dev.conf.template. Its two server blocks both
# `include /etc/nginx/nginx_dev_common.conf`, so the shared partial has to be
# rendered through the SAME allow-list, into exactly that path, first.
# rendered through the SAME allow-list, into exactly that path, first. (That
# partial in turn includes nginx_routes.conf, rendered above.)
envsubst "$ENVSUBST_VARS" \
</etc/nginx/nginx_dev_common.conf.template \
>/etc/nginx/nginx_dev_common.conf
@@ -122,7 +156,8 @@ if [ "$DEV_MODE" = "true" ]; then
CONFIG_MODE=dev
elif [ -f "/etc/letsencrypt/live/$DOMAIN/fullchain.pem" ] && [ -f "/etc/letsencrypt/live/$DOMAIN/privkey.pem" ]; then
echo "Certificates found. Using production nginx config."
# In production with certificates already existing, so use nginx.conf.template
# In production with certificates already existing, so use nginx.conf.template.
# It includes nginx_routes.conf, rendered above.
envsubst "$ENVSUBST_VARS" \
</etc/nginx/nginx.conf.template \
>/etc/nginx/nginx.conf
@@ -130,7 +165,9 @@ elif [ -f "/etc/letsencrypt/live/$DOMAIN/fullchain.pem" ] && [ -f "/etc/letsencr
else
echo "Certificates NOT found. Using setup nginx config."
# In production with no certificates, so use nginx_setup.conf.template and will need restart after generation
# Only ${DOMAIN} is substituted: the setup config has no upstreams at all.
# Only ${DOMAIN} is substituted: the setup config has no upstreams at all
# (and does not include nginx_routes.conf — that file is on disk only so the
# certificate watcher can switch to the production config later).
envsubst '${DOMAIN}' </etc/nginx/nginx_setup.conf.template >/etc/nginx/nginx.conf
CONFIG_MODE=setup
fi
@@ -202,6 +239,12 @@ CERT_WATCH_INTERVAL="${CERT_WATCH_INTERVAL:-60}"
# Render the production template to a temp file, validate it, and only then
# install it. Returns non-zero (installing nothing) if either step fails.
# The candidate `include`s /etc/nginx/nginx_routes.conf by absolute path, so
# `nginx -t` here validates the shared route table too; that file was rendered
# once at the top of this script and is deliberately NOT re-rendered here (it
# cannot have changed — see the comment where it is rendered — and rewriting a
# file the running nginx may be about to re-read would only add a window in
# which it is truncated).
render_prod_config() {
_candidate=/tmp/nginx.conf.candidate
envsubst "$ENVSUBST_VARS" </etc/nginx/nginx.conf.template >"$_candidate" 2>/dev/null || return 1
+42 -291
View File
@@ -11,7 +11,7 @@
# TEMPLATING
# Only the names in the envsubst allow-list in nginx/entrypoint.sh are
# substituted: DOMAIN, BACKEND_HOST/PORT/ENDPOINT, ICECAST_*, GITEA_*,
# SILVERBULLET_*, PYTHON_*, UPTIMEKUMA_*, WALLABAG_*. Every other dollar
# SILVERBULLET_*, PYTHON_*. Every other dollar
# token in this file is an nginx RUNTIME variable (host, remote_addr, uri,
# http_upgrade, proxy_add_x_forwarded_for, binary_remote_addr, request_uri,
# scheme, http_cookie) and must be left alone — that restriction is the whole
@@ -25,6 +25,16 @@
# is exactly one canonical origin (important: cookies,
# CORS and the SPA all assume www).
# 3. :443 www -> the real site.
#
# WHERE THE PROXY ROUTES ARE
# Not in this file. The reverse-proxied locations (/api, /radio, /gitea,
# /notes, /sb, /py and the admin-gate subrequest) and the `set $upstream_*`
# variables are shared with dev and live in nginx_routes.conf.template,
# which the www server block includes. ADD NEW PROXIED ROUTES THERE. What
# stays here is what only production has: TLS, the redirects, the security
# headers, static-asset caching, the SPA fallback, the /uploads/ blocks
# (which carry the security headers), the `graphql` rate-limit zone and its
# location, and the limit_req_zone declarations the shared routes refer to.
# =============================================================================
events {
worker_connections 1024;
@@ -76,7 +86,9 @@ http {
# This is an abuse ceiling, not a quota.
# graphql 10r/s burst=10 - tighter than REST because a single GraphQL
# query can be arbitrarily expensive to resolve.
# (Production only; the dev template omits it.)
# (Production only; the dev template omits it.
# Its location is at the bottom of this file,
# not in the shared route table.)
# upload 5r/m burst=3 - uploads are 50MB-capable and hit disk; this
# bounds how fast one IP can fill the volume.
# hotel_search 3r/m burst=2 - each request holds an upstream call to
@@ -89,6 +101,11 @@ http {
# CDN or upstream proxy in front), that is correct. If anything is ever put
# in front, these zones must switch to a trusted X-Forwarded-For or every
# visitor will share one bucket.
#
# login, api, upload and hotel_search are USED from
# nginx_routes.conf.template, which dev includes too — so
# nginx_dev.conf.template must declare the same four zones, or the dev
# config fails to load with "zero size shared memory zone".
limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;
limit_req_zone $binary_remote_addr zone=api:10m rate=30r/s;
limit_req_zone $binary_remote_addr zone=graphql:10m rate=10r/s;
@@ -161,12 +178,9 @@ http {
http2 on;
server_name www.$DOMAIN;
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 `set $upstream_*` variables used by proxy_pass are declared in
# nginx_routes.conf (included below), alongside the routes that use
# them.
root /etc/nginx/html;
index index.html;
@@ -178,6 +192,9 @@ http {
# included there instead of here, because any location that declares
# so much as one add_header of its own otherwise inherits none of
# these (nginx's add_header inheritance is all-or-nothing).
# The shared proxy routes in nginx_routes.conf rely on exactly this
# server-level include: none of them declares an add_header, so they
# all inherit these headers here, and inherit nothing in dev.
include /etc/nginx/security_headers.conf;
# Vite hashed assets - immutable, cache 1 year
@@ -273,80 +290,25 @@ http {
include /etc/nginx/security_headers.conf;
}
# ---- Backend API -----------------------------------------------------
# Two patterns repeat through every proxied location below:
# ---- Shared proxy route table ----------------------------------------
# Every reverse-proxied location (/api, /radio, /gitea, /notes, /sb,
# /py), the admin auth_request gate and the `set $upstream_*` variables
# come from nginx_routes.conf.template, rendered by the entrypoint to
# this path and shared with the dev config. The prefix-strip rewrite,
# the forwarding headers and the websocket upgrade are annotated there.
#
# 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, /messages/upload and /graphql blocks
# 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/messages/upload {
limit_req zone=upload 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;
}
# Position matters for one thing only: regex locations are tried in
# file order, so the ACME regex above stays ahead of the /notes and
# /py/hotels regexes inside this include, as it always was.
include /etc/nginx/nginx_routes.conf;
# GraphQL, PRODUCTION ONLY — which is why it is here and not in the
# shared table. Longest-prefix matching makes it win over the shared
# $BACKEND_ENDPOINT/ catch-all, swapping the general `api` limit for
# the tighter `graphql` zone declared at the top of this file. Dev has
# no such location, so GraphQL there falls under `api`. Apart from the
# limit_req line the body must stay identical to $BACKEND_ENDPOINT/ in
# nginx_routes.conf.template.
location $BACKEND_ENDPOINT/graphql {
limit_req zone=graphql burst=10 nodelay;
rewrite ^$BACKEND_ENDPOINT/(.*)$ /$1 break;
@@ -357,217 +319,6 @@ http {
proxy_set_header X-Forwarded-Proto $scheme;
}
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/;
}
# 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;
}
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;
}
# ---- Admin gate (/sb/, /radio/admin/, /uploads/private/) ----
# `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.
location = /internal/auth/admin-validate {
internal;
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;
}
}
}
+12 -6
View File
@@ -11,8 +11,7 @@
# for Vite's HMR websocket, not for the app.
# - No HTTP->HTTPS redirect and no apex->www redirect: BOTH :80 and :443
# serve the full site, so http://localhost just works. The two server
# blocks are therefore near-identical copies of each other (see the
# duplication note in DEPLOYMENT.md).
# blocks therefore share one body, nginx_dev_common.conf.template.
# - TLS uses the self-signed /etc/letsencrypt/live/localhost/ certificate that
# the entrypoint generates, not a Let's Encrypt one. Browsers will warn.
# - No HSTS or other security headers — HSTS on localhost would poison the
@@ -26,10 +25,13 @@
# Same envsubst allow-list as production. Every other dollar token is an
# nginx runtime variable and must survive substitution untouched.
#
# For the rate-limit reasoning, the prefix-strip rewrite, the four forwarding
# headers, the websocket upgrade block and the auth_request admin gate, see the
# fully-annotated equivalents in nginx.conf.template — the mechanics here are
# identical.
# INCLUDE CHAIN
# this file -> nginx_dev_common.conf (once per server block: the dev-only
# /uploads/ and `/` locations) -> nginx_routes.conf (the proxy route table
# shared with production). The prefix-strip rewrite, the four forwarding
# headers, the websocket upgrade block and the auth_request admin gate are
# annotated in nginx_routes.conf.template; the rate-limit reasoning is in
# nginx.conf.template.
# =============================================================================
events {
worker_connections 1024;
@@ -46,6 +48,10 @@ http {
client_max_body_size 50M;
# These four zones are referenced by limit_req lines in the SHARED
# nginx_routes.conf.template, so they must exist here with the same names
# as in nginx.conf.template or nginx refuses to load the config. Rates are
# kept equal to production so a limit that would bite there bites here too.
limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;
limit_req_zone $binary_remote_addr zone=api:10m rate=30r/s;
limit_req_zone $binary_remote_addr zone=upload:10m rate=5r/m;
+23 -216
View File
@@ -1,5 +1,6 @@
# =============================================================================
# nginx_dev.conf.template — SHARED BODY of the dev :80 and :443 server blocks.
# nginx_dev_common.conf.template — SHARED BODY of the dev :80 and :443 server
# blocks.
#
# WHY THIS FILE EXISTS
# In dev the :80 and :443 server blocks are byte-for-byte identical apart
@@ -16,21 +17,19 @@
# the entrypoint, or it will reach nginx unsubstituted.
#
# WHAT BELONGS HERE
# Everything inside a `server { ... }` block: the `set $upstream_*` vars and
# every `location`. NOT `listen`, `server_name` or the ssl_certificate lines
# (those differ between the two blocks), and NOT the enclosing braces — this
# file must be brace-balanced on its own.
# Only what dev does DIFFERENTLY from production inside a server block: the
# /uploads/ locations without security headers, and `/` proxied to Vite.
# Everything else — the `set $upstream_*` vars and every reverse-proxied
# route — is in nginx_routes.conf.template, shared with production and
# included at the bottom of this file. ADD NEW PROXIED ROUTES THERE, not
# here.
# NOT `listen`, `server_name` or the ssl_certificate lines (those differ
# between the two blocks), and NOT the enclosing braces — this file must be
# brace-balanced on its own.
#
# This is the DEV file only. Production uses a single :443 server block in
# nginx.conf.template and needs no partial.
# This is the DEV file only. Production's single :443 www server block in
# nginx.conf.template includes nginx_routes.conf directly.
# =============================================================================
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;
# PRIVATE attachments (admin-only). Attachments on *private* chat
# messages are written by the backend to /backend/uploads/private/ and
# must not be readable by the public, so this subpath is put behind the
@@ -48,6 +47,12 @@
add_header Content-Security-Policy "default-src 'none'; img-src 'self'; style-src 'none'; script-src 'none'" always;
}
# Both /uploads/ blocks are the production ones MINUS
# `include security_headers.conf`: that file carries HSTS, which must
# never be sent from localhost. That one line is why they are not in
# the shared route table (see WHAT DOES NOT in
# nginx_routes.conf.template). Keep the rest in step with
# nginx.conf.template.
location /uploads/ {
alias /uploads/;
add_header X-Content-Type-Options nosniff always;
@@ -55,6 +60,7 @@
add_header Content-Security-Policy "default-src 'none'; img-src 'self'; style-src 'none'; script-src 'none'" always;
}
# The Vite dev server; Upgrade/Connection carry its HMR websocket.
location / {
proxy_pass http://vue:5173;
proxy_http_version 1.1;
@@ -63,205 +69,6 @@
proxy_set_header Host $host;
}
location $BACKEND_ENDPOINT {
return 301 $BACKEND_ENDPOINT/;
}
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/messages/upload {
limit_req zone=upload 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/ {
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/;
}
# 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;
}
location /notes {
return 301 /notes/;
}
# PUBLIC notes viewer (read-only SilverBullet). The deny blocks are
# the privacy boundary: SB_SPACE_IGNORE hides files from the list but
# NOT from a direct /.fs/ fetch, a page URL (server-rendered), or
# /.fs/.git/. Full explanation in nginx.conf.template; keep the two in
# step.
location ~* ^/notes/(.*/)?(private|templates)(/|$) {
return 404;
}
location ~ ^/notes/.+/\. {
return 404;
}
location ^~ /notes/.revisions {
return 404;
}
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;
}
location = /internal/auth/admin-validate {
internal;
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;
}
# Every other route, shared with production. This file has no regex
# locations of its own, so where the include sits is cosmetic.
include /etc/nginx/nginx_routes.conf;
+367
View File
@@ -0,0 +1,367 @@
# =============================================================================
# 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;
# ---- 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 /messages/upload 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/messages/upload {
limit_req zone=upload 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;
}
# 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/;
}
# 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;
}
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;
}
# ---- Admin gate (/sb/, /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.
location = /internal/auth/admin-validate {
internal;
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;
}