# Project Guidelines ## Overview This repository is **not an application codebase** — it is a **Docker-based deployment/infrastructure configuration** for exposing a Java web application behind an Nginx reverse proxy with automatic TLS certificate management via Let's Encrypt / Certbot. The real website this is used for is `www.elenabaracchini.it`, but the configuration is written to be reusable for any domain (placeholders use `example.com`). Primary documentation (in Italian) lives in [README.md](README.md). Keep it in sync with any changes. ## Repository Layout ``` . ├── docker-compose.yml # Orchestrates the 3 services: app, nginx, certbot ├── init-letsencrypt.sh # First-time certificate bootstrap script ├── renew-certificates.sh # Interactive manual renewal helper ├── certbot-entrypoint.sh # Certbot container entrypoint (auto-renew loop OR passthrough) ├── nginx/ │ ├── nginx.conf # Global Nginx config (http block, gzip, logging) │ └── conf.d/ │ └── app.conf # Virtual host: HTTP→HTTPS redirect + HTTPS reverse proxy └── README.md # Full setup/usage/troubleshooting guide (Italian) ``` ## Architecture - **`app`**: the Java web application container (image `your-java-app:latest`, placeholder). Not exposed directly; only reachable through Nginx on the internal `app-network`. Listens on port `8080`. - **`nginx`**: reverse proxy (`nginx:alpine`), the only service bound to host ports `80`/`443`. Mounts config read-only and the shared Let's Encrypt volumes read-only. - **`certbot`**: `certbot/certbot:latest` driven by `certbot-entrypoint.sh`. - **No args** → runs the auto-renewal loop (renew check every 12h). - **With args** → execs the given `certbot` command (used by `docker-compose run --rm certbot ...`). - **Shared volumes**: `certbot-webroot`, `certbot-certs`, `certbot-lib`, `certbot-logs` connect certbot and nginx for ACME challenges and certificate files. ## Conventions - **Comments & docs are written in Italian.** Match this language when editing scripts, config comments, and the README. - Shell scripts use `#!/bin/bash` (except `certbot-entrypoint.sh`, which targets the Alpine shell with `#!/bin/sh` — keep it POSIX-compatible). Scripts use `set -e`. - Domain references: use `example.com` as the placeholder in committed config. The real domain (`elenabaracchini.it`) is substituted at runtime by `init-letsencrypt.sh`. - Nginx config is split: global settings in `nginx.conf`, per-site server blocks in `conf.d/*.conf`. - Preserve the existing security posture in `app.conf` (TLS 1.2/1.3, HSTS, security headers, OCSP stapling) when making changes. ## Common Commands ```bash # First-time certificate setup (use staging=1 for testing to avoid rate limits) ./init-letsencrypt.sh [0|1] # Full stack up / down docker-compose up -d docker-compose down # Validate & reload nginx without downtime docker-compose exec nginx nginx -t docker-compose exec nginx nginx -s reload # Certificate management docker-compose run --rm certbot certificates docker-compose run --rm certbot renew --dry-run ./renew-certificates.sh # Logs docker-compose logs -f nginx docker-compose logs -f app docker-compose logs certbot ``` ## Validation There is no build or test suite. Validate changes by: - `docker-compose config` — verify the compose file parses. - `docker-compose exec nginx nginx -t` — validate Nginx config syntax (requires nginx running). - Use Let's Encrypt **staging** (`--staging` / `init-letsencrypt.sh ... 1`) before production to avoid hitting rate limits (50 certs/domain/week, 5 duplicates/week). ## Things to Watch Out For - **Do not expose `app` ports directly** on the host; traffic must flow through Nginx. - **Never commit secrets** (JWT secrets, DB passwords, etc.) — pass them via environment variables. - When changing the domain, remember both `app.conf` server blocks and the Let's Encrypt cert paths (`/etc/letsencrypt/live//...`) must match. - `README.md` currently contains unresolved Git merge conflict markers (`<<<<<<<`, `=======`, `>>>>>>>`) around the file-structure section — resolve these if you touch that area.