Opt-in and built so Garage can never take the site down: - the backend writes to the bucket only once S3_ENDPOINT is set, and falls back to the uploads volume (with a log line) if a write fails; - nginx serves /uploads/ from the volume first and Garage's anonymous website endpoint second, so every existing URL keeps working and nginx boots with no garage container; - nothing depends_on garage and no variable is required, so a missing secret cannot fail a deploy. Private attachments stay on disk, since nginx cannot gate a bucket. garage/bootstrap.sh sets up the layout, bucket, key and website access; the runbook is "Garage" in DEPLOYMENT.md. Also lifts the body limit on the internal auth subrequest, which 413'd large uploads to gated locations, and reserves the garage and dozzle page slugs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
85 lines
4.4 KiB
Plaintext
85 lines
4.4 KiB
Plaintext
# =============================================================================
|
|
# 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
|
|
# from `listen` and the self-signed `ssl_certificate` pair. They used to be
|
|
# ~190 duplicated lines, so every routing fix had to be made twice and could
|
|
# silently drift. Both blocks now `include` this partial instead.
|
|
#
|
|
# HOW IT IS RENDERED
|
|
# nginx/entrypoint.sh runs the SAME envsubst allow-list over this file as
|
|
# over nginx_dev.conf.template, writing the result to
|
|
# /etc/nginx/nginx_dev_common.conf — which is exactly the path the two
|
|
# `include` directives in the rendered nginx.conf point at. If you add
|
|
# a new substituted variable here, it must also be added to ENVSUBST_VARS in
|
|
# the entrypoint, or it will reach nginx unsubstituted.
|
|
#
|
|
# WHAT BELONGS HERE
|
|
# 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's single :443 www server block in
|
|
# nginx.conf.template includes nginx_routes.conf directly.
|
|
# =============================================================================
|
|
# 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
|
|
# same admin `auth_request` used for /sb/. nginx picks
|
|
# the LONGEST matching prefix location, so this block wins over the
|
|
# public /uploads/ block below for /uploads/private/* regardless of
|
|
# ordering. Same three hardening headers as the public block, because
|
|
# the bytes are just as attacker-supplied.
|
|
location /uploads/private/ {
|
|
auth_request /internal/auth/admin-validate;
|
|
error_page 401 403 = @auth_denied;
|
|
alias /uploads/private/;
|
|
add_header X-Content-Type-Options nosniff always;
|
|
add_header Content-Disposition "inline" always;
|
|
add_header Content-Security-Policy "default-src 'none'; img-src 'self'; style-src 'none'; script-src 'none'" always;
|
|
}
|
|
|
|
# The /uploads/ blocks (and @uploads_bucket) 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/ {
|
|
root /;
|
|
try_files $uri @uploads_bucket;
|
|
add_header X-Content-Type-Options nosniff always;
|
|
add_header Content-Disposition "inline" always;
|
|
add_header Content-Security-Policy "default-src 'none'; img-src 'self'; style-src 'none'; script-src 'none'" always;
|
|
}
|
|
|
|
location @uploads_bucket {
|
|
rewrite ^/uploads/(.*)$ /$1 break;
|
|
proxy_pass $upstream_garage_web;
|
|
proxy_set_header Host uploads.web.garage;
|
|
add_header X-Content-Type-Options nosniff always;
|
|
add_header Content-Disposition "inline" always;
|
|
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;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection "upgrade";
|
|
proxy_set_header Host $host;
|
|
}
|
|
|
|
# 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;
|