Documenta comandi di validazione, architettura dello stack (blog, postgresql, nginx, certbot), il bootstrap dei certificati e le convenzioni facili da rompere (header di sicurezza, resolver, pin delle immagini). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
7.3 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
What this repo is
This is not an application codebase. It is a Docker Compose deployment for exposing a JHipster
(Spring Boot) web app behind an Nginx reverse proxy with Let's Encrypt/Certbot TLS. There is no
build step, no test suite, and no application source here. The real site is www.elenabaracchini.it,
but every committed file uses the placeholder example.com.
Comments, scripts and the README are written in Italian. Match that language when editing them,
and keep README.md in sync with any behavioural change (it is the primary user-facing doc).
Commands
# Validate changes (the only "tests" that exist)
docker-compose config # compose file parses, env guards (:?) satisfied
docker-compose exec nginx nginx -t # nginx syntax (needs the nginx container running)
# First-time certificate bootstrap (staging=1 first, to avoid LE rate limits)
./init-letsencrypt.sh <domain> <email> [0|1]
# Run / stop the stack
docker-compose up -d
docker-compose down
# Reload nginx without downtime (always run nginx -t first: reload exits 0 on invalid config)
docker-compose exec nginx nginx -t && docker-compose exec nginx nginx -s reload
# Certificates (certbot entrypoint passes args straight to certbot)
docker-compose run --rm certbot certificates
docker-compose run --rm certbot renew --dry-run
docker-compose run --rm certbot delete --cert-name <domain> # needed before staging -> prod
./renew-certificates.sh # interactive manual renewal
# Logs
docker-compose logs -f nginx | blog | postgresql | certbot
.env (gitignored) must define BLOG_IMAGE and POSTGRES_PASSWORD; docker-compose.yml uses
${VAR:?} guards so any compose command fails loudly without them. .env.example deliberately leaves
POSTGRES_PASSWORD empty so the guard cannot be satisfied by a placeholder.
Architecture
Four services on one internal bridge network (app-network). Only nginx publishes host ports
(80/443); blog:8080 and postgresql:5432 are intentionally not exposed.
blog— the JHipster app, image from${BLOG_IMAGE},prodprofile, datasource pointed atpostgresql. Healthcheck hits/management/healthwithwget(slim JRE images lack curl). Starts only afterpostgresqlis healthy;nginxdepends onblog.postgresql—postgres:17.11, data in thepostgresql-datavolume, explicitPOSTGRES_DB.nginx—nginx:1.30-alpine, config bind-mounted read-only, cert volumes read-only. Itscommandwrapsnginx -g 'daemon off;'in a loop that runsnginx -s reloadevery 6h: nginx loads certs into memory once, so without this it would serve an expired cert after renewal.certbot—certbot/certbot:v5.4.0withcertbot-entrypoint.shas entrypoint. No args → infinitecertbot renewloop every 12h (whatup -druns). With args →exec certbot "$@"(whatdocker-compose run --rm certbot ...uses). Sharescertbot-webroot(ACME challenge files) andcertbot-certs(/etc/letsencrypt) with nginx via named volumes.
Nginx layout
nginx/nginx.conf— http-level settings, logging, gzip,server_tokens off, and the$connection_upgrademap used for WebSocket upgrade. Includesconf.d/*.conf.nginx/conf.d/app.conf— HTTP→HTTPS redirect server + HTTPS reverse-proxy server.nginx/conf.d/security-headers.inc— HSTS / nosniff /X-XSS-Protection: 0. The.incextension is deliberate so the*.confglob does not load it as a standalone file.
The certificate bootstrap (why init-letsencrypt.sh is shaped the way it is)
On a fresh host the HTTPS server block in app.conf cannot load (no cert files yet), so nginx would
refuse to start. The script therefore: backs up app.conf to app.conf.bak, writes a temporary
HTTP-only config serving /.well-known/acme-challenge/, starts nginx with --no-deps (so blog/
postgresql and a populated .env are not required for the ACME phase), waits for nginx to answer,
runs certbot certonly --webroot --non-interactive, then restores the backup via an EXIT trap,
seds example.com → real domain, brings up the full stack, and runs nginx -t before
nginx -s reload. nginx/conf.d/*.bak is gitignored; the script also recovers from a leftover
.bak of an interrupted run. Because certonly is --non-interactive, an existing (e.g. staging)
lineage makes it fail rather than prompt: delete the lineage or use --force-renewal first.
Conventions and things that are easy to break
- Keep
example.comin committed config. The real domain is substituted at deploy time by the script; never commit a domain-specificapp.conf. When changing domain handling, bothapp.confserver blocks and the/etc/letsencrypt/live/<domain>/paths must agree. - Image pinning: no
:latestanywhere (compose uses exact tags;BLOG_IMAGEshould be a tag or digest). A silent certbot/nginx upgrade can break auto-renewal. - Security header ownership. JHipster already emits
Content-Security-Policy,X-Frame-Options,Referrer-PolicyandPermissions-Policy; nginxadd_headerdoes not replace upstream headers, so adding them in nginx produces duplicates (two CSPs = most restrictive intersection, can break the SPA bundle). Nginx only sets HSTS (withoutincludeSubDomains/preload, by design) and the two non-conflicting headers. Useproxy_hide_headerif nginx must take ownership. add_headerinside alocationdiscards all inheritedadd_headers. Any new location with its ownadd_headermust re-include security-headers.inc./managementis 404'd at nginx (location ^~ /management) so actuator/prometheus endpoints are never public; the healthcheck reaches it from inside the container. Do not enable the JHipsterapi-docsprofile in prod for the same reason (nginx proxies all of/).proxy_passuses a variable plusresolver 127.0.0.11so nginx re-resolvesblogat runtime; a literal hostname is resolved once at startup and yields 502s afterbloggets a new IP. Keep that pattern for any new upstream.- No per-vhost
access_log/error_loginapp.conf: only the default paths are linked to stdout/stderr in the official image, so dedicated files would be invisible todocker-compose logsand never rotated. - OCSP stapling and DHE ciphers were removed on purpose (Let's Encrypt dropped OCSP; no
ssl_dhparammeans DHE would never be negotiated). Don't reintroduce them without the matching config. Preserve TLS 1.2/1.3 only and the Mozilla-intermediate cipher list. - Docker does not restart
unhealthycontainers; healthchecks here only drive start order (depends_on: condition: service_healthy) andpsstatus. - Shell scripts:
init-letsencrypt.shandrenew-certificates.share#!/bin/bashwithset -e;certbot-entrypoint.shruns inside Alpine and must stay POSIX#!/bin/sh. All three must remain executable (chmod +x), since the entrypoint is bind-mounted into the container. .junie/guidelines.mdis an older agent-guidance file that predates theblog/postgresqlsplit and the OCSP removal; prefer this file and the README where they disagree.