Reference
Architecture
Nginx Proxy Guard consists of five containers started with Docker Compose. Every setting is stored in the database; the API renders nginx configuration files from it, checks them and applies them. The database is the source of truth, and the nginx files are generated from it.
Containers
| Service | Container | Role | Ports |
|---|---|---|---|
nginx | npg-proxy | The actual reverse proxy, with ModSecurity and the OWASP CRS. The cloudflared binary for Cloudflare Tunnel is part of this image. | Host network: 80 and 443 (TCP), 443 (UDP) for HTTP/3 |
api | npg-api | Management API, nginx configuration rendering and applying, log collection, certificate issuance, scheduled jobs | 127.0.0.1:9080 → 8080 |
ui | npg-ui | The admin panel (React). Its own nginx serves the panel files and passes /api to the API container. | 81 → 443 (HTTPS) |
db | npg-db | TimescaleDB (PostgreSQL). Stores settings and logs. | internal 5432 |
valkey | npg-valkey | Cache and rate-limit counters. Optional. | internal 6379 |
The main components are nginx 1.30.7, ModSecurity 3.0.15, OWASP CRS 4.26.0, TimescaleDB PostgreSQL 17 and Valkey 9. The API is written in Go and the admin panel in React.
npg-proxy uses the host network so it sees visitors' real IP addresses without extra setup. NGINX_HTTP_PORT and NGINX_HTTPS_PORT are therefore the host's ports.
The API container mounts the Docker socket (/var/run/docker.sock). Through it the API runs nginx -t and reloads inside npg-proxy, and reads the container list (for the Docker container picker on proxy hosts), container logs and resource usage.
Volumes
| Volume | Mounted at | Content |
|---|---|---|
npg_nginx_data | /etc/nginx (shared by api and nginx) | nginx configuration, certificates and ModSecurity configuration written by the API, and the raw log files written by nginx |
npg_api_data | /app/data (api) | Backup files |
npg_postgres_data | database data | Settings and logs |
npg_valkey_data | Valkey data | Cache |
npg_ui_data | /app/ssl (ui) | The admin panel's self-signed certificate |
The path of a request
visitor
│ 80/443 (TCP), 443 (UDP, HTTP/3)
▼
npg-proxy (nginx, host network)
├─ the requested domain selects the proxy host (unknown domains go to the default server)
├─ checks configured on that host: banned IPs, blocklist subscriptions,
│ geo and cloud blocking, bot filter, access list, rate limit,
│ URI and exploit blocking, ForwardAuth
├─ ModSecurity + OWASP CRS (per-host mode and paranoia level)
└─ passed to the upstream (the backend service)
└─ recorded: access log file, ModSecurity eventsA blocked request never reaches the upstream; it gets a response such as 403, and the access log records the block reason. Which trusted list skips which check is listed in Trusted IPs, exceptions and precedence.
How settings are applied
Whatever you save in the admin panel, the sequence is the same.
- The API records the change in the database.
- It renders the nginx configuration files from the database. Files are written to a temporary file and then renamed into place, so no half-written file is ever left.
- It checks the whole configuration with
nginx -tinsidenpg-proxy. - If the check passes, nginx is reloaded. If not, nothing is reloaded, the previous configuration file is restored and the error is shown. For a newly created proxy host the database record is rolled back too.
nginx operations run one at a time. If the check passes but the running nginx refuses the reload, the change stays saved and an error is reported; this can also be sent as the nginx reload failed notification.
The Sync All Configs button at the top right regenerates the configuration of every proxy host and redirect host from the database. If one host's configuration makes nginx -t fail, that host's configuration is set aside and the host is marked with an error status, while all other hosts keep working. Hosts in the error state are flagged in the proxy host list, and the editor shows the cause.
Log storage
- nginx writes the access log to
/etc/nginx/logs/access_raw.log(stream_raw.logfor stream hosts). - The API's log collector follows that file, parses each line, adds country data from GeoIP and stores it in the database. ModSecurity events and nginx errors are read from the
npg-proxycontainer output. - Logs are stored in a TimescaleDB hypertable, and chunks older than one day are compressed. Logs past the retention period of their type are deleted.
- The raw log files are checked for size every hour and rotated, and they are also rotated every day at midnight.
TimescaleDB is used for log compression and deletion by time range. On a home server, logs are usually what fills the disk, and compression shrinks them considerably. Retention and raw file settings are in Settings and maintenance.
Running without Valkey
Valkey is optional. With REDIS_URL empty, the API keeps its cache and the per-minute API rate-limit counters in its own memory (bounded to 4–64 MiB, NPG_LOCAL_CACHE_MAX_MB). The same applies while a configured Valkey has not connected yet. What changes:
| Feature | Without Valkey |
|---|---|
| Cache, per-minute API and sign-in rate limits | Counted in the API process's memory |
| fail2ban counting | Counted in the API process's memory |
| Live log during certificate issuance | Empty |
| Database-backed login lockout (5 attempts in 15 minutes), the API's per-IP per-second limit | Unchanged |
If a Valkey that was connected stops later, the API does not switch to the in-memory mode. Cache reads then go to the database, and the per-minute rate limit lets requests through on errors. Configuration is described in Environment variables.
Start-up and upgrades
- The API brings the database schema up to date automatically when it starts. An upgrade is pulling the new images and recreating the containers (Updating and backups).
- The API starts accepting requests only after it has reconciled the configuration of every host. With many hosts this can take a few minutes, and the compose health check allows up to six minutes for it.
Scheduled jobs
The API runs these jobs in the background.
| Job | Interval |
|---|---|
| Certificate renewal | Checked every 6 hours, renewed from 30 days before expiry |
| Blocklist subscription refresh | Checked every 10 minutes, per each subscription's refresh setting |
| DDNS public IP check | 5 minutes by default |
| Container IP re-check for hosts that target a container | 30 seconds by default |
| Automatic backup | The configured cron schedule |
| Raw log rotation | Hourly |
| Server resource recording | 30 seconds |
| Disk usage check | 1 minute |
| Log retention cleanup | Daily |
Container hardening
The stock docker-compose.yml reduces container privileges. api drops every Linux capability except DAC_OVERRIDE, which it needs to write configuration files, and sets no-new-privileges. ui runs nginx as a non-root user with only NET_BIND_SERVICE for binding port 443. nginx sets no-new-privileges. Do not expose the admin panel (port 81) to the internet directly; keep it on your LAN or behind a VPN.