services: # TimescaleDB (PostgreSQL with time-series optimization) db: image: timescale/timescaledb:latest-pg17 container_name: npg-db restart: unless-stopped # Log rotation caps, so container logs cannot fill the disk — the failure # that actually bites a home server. Pinning the driver has a cost: Synology # DSM's Container Manager reads its own log backend and shows nothing for a # container that sets json-file explicitly. If you run DSM and want logs in # its viewer, comment this block out; `docker logs` works either way, and # you then rely on the daemon's own rotation settings. (#251) logging: driver: "json-file" options: max-size: "50m" max-file: "3" environment: TZ: ${TZ:-UTC} POSTGRES_USER: ${DB_USER:-postgres} POSTGRES_PASSWORD: ${DB_PASSWORD:-postgres} POSTGRES_DB: ${DB_NAME:-nginx_proxy_guard} command: postgres -c timezone=${TZ:-UTC} -c log_timezone=${TZ:-UTC} -c shared_preload_libraries=timescaledb -c timescaledb.telemetry_level=off -c max_locks_per_transaction=512 volumes: - postgres_data:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-postgres}"] interval: 10s timeout: 5s retries: 10 start_period: 30s # Valkey (Redis-compatible) for caching valkey: image: valkey/valkey:9-alpine container_name: npg-valkey restart: unless-stopped logging: driver: "json-file" options: max-size: "10m" max-file: "3" environment: TZ: ${TZ:-UTC} command: > valkey-server --maxmemory 256mb --maxmemory-policy allkeys-lru --appendonly yes --appendfsync everysec volumes: - valkey_data:/data healthcheck: test: ["CMD", "valkey-cli", "ping"] interval: 10s timeout: 5s retries: 5 start_period: 10s # Go API Server api: image: svrforum/nginxproxyguard-api:latest # build: # context: ./api # dockerfile: Dockerfile container_name: npg-api restart: unless-stopped # Container hardening (H8 / MEDIUM-8). # no-new-privileges blocks setuid privilege escalation even though the API # still runs as root (it needs docker.sock; see api/Dockerfile for why it is # not switched to a non-root user). cap_drop ALL removes every Linux # capability; DAC_OVERRIDE is re-added because the shared /etc/nginx volume # dirs (conf.d, stream.d, certs, modsec) are owned by the nginx user # (uid 101, mode 755) — without it even root gets EACCES writing configs. # # FOLLOW-UP (larger change, tracked separately): front docker.sock with # tecnativa/docker-socket-proxy so the API can only LIST/INSPECT/EXEC the # nginx container and can never create containers. Sketch: # docker-socket-proxy: # image: tecnativa/docker-socket-proxy # environment: { CONTAINERS: 1, EXEC: 1, POST: 1 } # tighten further # volumes: [ "/var/run/docker.sock:/var/run/docker.sock:ro" ] # then point the api at tcp://docker-socket-proxy:2375 and drop the direct # docker.sock mount below + drop root in api/Dockerfile. security_opt: - "no-new-privileges:true" cap_drop: - ALL cap_add: - DAC_OVERRIDE logging: driver: "json-file" options: max-size: "100m" max-file: "5" extra_hosts: - "host.docker.internal:host-gateway" environment: TZ: ${TZ:-UTC} PORT: "8080" DATABASE_URL: postgres://${DB_USER:-postgres}:${DB_PASSWORD:-postgres}@db:5432/${DB_NAME:-nginx_proxy_guard}?sslmode=disable # Set REDIS_URL= (empty) in .env to run without Valkey; the API then # caches in its own memory, capped by NPG_LOCAL_CACHE_MAX_MB (unset = # sized from the container's memory limit, 0 = off). REDIS_URL: ${REDIS_URL-redis://valkey:6379/0} NPG_LOCAL_CACHE_MAX_MB: ${NPG_LOCAL_CACHE_MAX_MB:-} JWT_SECRET: ${JWT_SECRET:-change-this-in-production-use-openssl-rand-hex-32} ENVIRONMENT: ${ENVIRONMENT:-production} # API rate limiting (per client IP per minute; counted in Valkey, or in the # API's own memory without it). 0 = off. # The login endpoints have their own separate budget so panel traffic can # never lock the operator out of the sign-in screen (#258). API_RATE_LIMIT_PER_MINUTE: ${API_RATE_LIMIT_PER_MINUTE:-} AUTH_RATE_LIMIT_PER_MINUTE: ${AUTH_RATE_LIMIT_PER_MINUTE:-} # Restrict which peers count as trusted proxy hops when resolving the # client IP from X-Forwarded-For (comma-separated CIDRs). Unset = trust # loopback/link-local/private ranges, which any stock install needs. TRUSTED_PROXY_CIDR: ${TRUSTED_PROXY_CIDR:-} # Domain entries in access lists. NPG_DNS_ENTRIES_DISABLED=1 is the # emergency switch: every domain entry stays closed, whatever the # settings say. NPG_DNS_ENTRIES_INTERVAL (a duration such as 60s, kept # within 5s-1h) overrides the check interval. Unset = the settings decide. # Values under 30s are for tests: every check sends about 8 DNS queries # per domain (more with a CNAME). NPG_DNS_ENTRIES_DISABLED: ${NPG_DNS_ENTRIES_DISABLED:-} NPG_DNS_ENTRIES_INTERVAL: ${NPG_DNS_ENTRIES_INTERVAL:-} NGINX_CONTAINER: npg-proxy NGINX_SKIP_TEST: "false" # nginx is in host mode, so use host.docker.internal to reach it NGINX_STATUS_URL: "http://host.docker.internal:${NGINX_HTTP_PORT:-80}/nginx_status" NGINX_ACCESS_LOG: "/etc/nginx/logs/access_raw.log" BACKUP_PATH: ${BACKUP_PATH:-/app/data/backups} # Docker API version - leave empty for auto-detection (recommended) DOCKER_API_VERSION: ${DOCKER_API_VERSION:-} # Custom nginx listen ports for host network mode (e.g., Synology DSM) NGINX_HTTP_PORT: ${NGINX_HTTP_PORT:-} NGINX_HTTPS_PORT: ${NGINX_HTTPS_PORT:-} # API host port - for host network mode (nginx uses this to reach API) API_HOST_PORT: ${API_HOST_PORT:-9080} # API host for nginx config generation. Leave empty to derive from # API_HOST_PORT (single source of truth); set only to override. Do NOT use # nested ${...} defaults here — old compose parsers emit them literally (#158). API_HOST: ${API_HOST:-} # Disk alerts: all optional, shown with their defaults. The API finds the # database container by itself; set NPG_DB_CONTAINER only if the dashboard # says the database disk is not measured. At the critical line older log # chunks are compressed early (lossless); "off" or "dryrun" changes that. # NPG_DB_CONTAINER: npg-db # NPG_DISK_WARN_PERCENT: "85" # NPG_DISK_CRITICAL_PERCENT: "90" # NPG_DISK_RECOVER_PERCENT: "80" # NPG_DISK_EMERGENCY_COMPRESS: "on" ports: # API host port - MUST NOT conflict with NGINX_HTTP_PORT - "127.0.0.1:${API_HOST_PORT:-9080}:8080" volumes: # Consolidated nginx data volume (shared with nginx container) - nginx_data:/etc/nginx:rw # Consolidated API data volume (config + backups) - api_data:/app/data:rw - /var/run/docker.sock:/var/run/docker.sock:ro # Optional: keep rotated raw logs on another disk or NAS mounted on the # host (fstab with nofail), then Logs -> Raw log files -> Archive. # - /mnt/nas/npg-raw-logs:/archive depends_on: db: condition: service_healthy valkey: condition: service_started healthcheck: test: ["CMD", "wget", "-q", "--spider", "http://localhost:8080/health"] interval: 30s timeout: 5s retries: 3 # Must exceed the API's startupTimeout (5m, bootstrap/container.go): the # API only begins listening after Startup() finishes reconciling every # host, so on large/slow installs a 60s window marked it unhealthy and # could churn before it ever listened. start_period: 360s # React UI (Production) - Admin Panel on port 81 (HTTPS) ui: image: svrforum/nginxproxyguard-ui:latest # build: # context: ./ui # dockerfile: Dockerfile container_name: npg-ui restart: unless-stopped # Container hardening (H8 / MEDIUM-8). # The UI runs nginx as the non-root "nginx" user (see ui/Dockerfile). We drop # ALL capabilities and re-add only NET_BIND_SERVICE, which the non-root nginx # needs to bind the privileged container port 443. # No no-new-privileges here: where Docker cannot open ports below 1024 to # non-root processes (kernels older than 4.11, e.g. Synology DSM 7), nginx # binds 443 only through the file capability on its binary, and # no-new-privileges makes the kernel drop it ("bind() to 0.0.0.0:443 # failed (13: Permission denied)"). With cap_drop ALL nothing in this # container can gain more than NET_BIND_SERVICE anyway. cap_drop: - ALL cap_add: - NET_BIND_SERVICE logging: driver: "json-file" options: max-size: "10m" max-file: "3" environment: TZ: ${TZ:-UTC} ports: - "${UI_PORT:-81}:443" volumes: - ui_data:/app/ssl:rw depends_on: - api # Nginx Reverse Proxy - HOST NETWORK MODE # Real client IPs are visible directly without proxy protocol nginx: image: svrforum/nginxproxyguard-nginx:latest # build: # context: ./nginx # dockerfile: Dockerfile container_name: npg-proxy restart: always network_mode: host # Container hardening (H8 / MEDIUM-8). # no-new-privileges blocks setuid privilege escalation. NOTE: do NOT cap_drop # this service — it runs nginx in host-network mode with a root master that # drops workers to the nginx user, so it needs CHOWN/SETUID/SETGID and binds # privileged 80/443; cap_drop ALL breaks boot (nginx [emerg] chown failed). # Capability-scoping a rootless nginx is a follow-up. security_opt: - "no-new-privileges:true" logging: driver: "json-file" options: max-size: "100m" max-file: "5" environment: TZ: ${TZ:-UTC} # sysctls not allowed in host network mode ulimits: nofile: soft: 65535 hard: 65535 volumes: # Consolidated nginx data volume - nginx_data:/etc/nginx:rw depends_on: - api healthcheck: test: ["CMD", "curl", "-f", "http://127.0.0.1:${NGINX_HTTP_PORT:-80}/health"] interval: 15s timeout: 5s retries: 3 start_period: 10s volumes: postgres_data: name: npg_postgres_data valkey_data: name: npg_valkey_data nginx_data: name: npg_nginx_data api_data: name: npg_api_data ui_data: name: npg_ui_data networks: default: name: npg-network