Nginx Proxy Guard

Getting started

Installation

By the end of this page NPG is running on your server and you are signed in to the admin UI with a new admin account.

Before you start

  • A linux/amd64 or linux/arm64 server with Docker 24.0 or later and Docker Compose v2
  • Ports 80, 443 (TCP and UDP) and 81 must be free on the server. If something else already uses 80 or 443, read "Changing ports" below first.
  • If you plan to use the WAF, 2 GB of RAM or more is recommended.
  • (Optional) A MaxMind account for country blocking. You enter it in the admin UI after installation.

Install

  1. Create the install directory and download two files.

    # 1. Create directory
    mkdir -p ~/nginx-proxy-guard && cd ~/nginx-proxy-guard
    
    # 2. Download files
    wget https://raw.githubusercontent.com/svrforum/nginxproxyguard/main/docker-compose.yml
    wget -O .env https://raw.githubusercontent.com/svrforum/nginxproxyguard/main/env.example
  2. Replace the database password and the application secret in .env with random values.

    # 3. Auto-generate secure secrets
    sed -i "s/DB_PASSWORD=.*/DB_PASSWORD=$(openssl rand -base64 24)/" .env
    sed -i "s/JWT_SECRET=.*/JWT_SECRET=$(openssl rand -hex 32)/" .env

    TZ in .env is the time zone used for logs and scheduled jobs. The downloaded file sets Asia/Seoul; change it if needed.

  3. Start the services.

    # 4. Start services
    docker compose up -d
  4. Check that every container is running.

    docker compose ps

    You should see npg-proxy, npg-api, npg-ui, npg-db and npg-valkey. On the first start the database is prepared and the schema is created, so the admin UI can take a little while to come up.

Addresses

ServiceAddress
Admin UIhttps://<server address>:81
HTTP proxyhttp://<server address>:80
HTTPS proxyhttps://<server address>:443

The admin UI uses a self-signed certificate, so the browser shows a certificate warning on the first visit. Open port 81 with https://, not http://.

First sign-in

  1. Sign in to the admin UI with username admin and password admin.

    Sign-in screen
    Sign-in screen
  2. The Initial Setup Required screen appears. Enter admin as the Current Password, choose a New Username and a New Password, and click Save New Credentials.

    • The new username must be something other than admin.
    • The new password must be at least 10 characters and contain an uppercase letter, a lowercase letter, a digit and a special character. Common passwords are refused.
    • Email is optional. If you will later sign in to this account through SSO, enter the address your SSO provider holds. You can change it in the settings at any time.
    Initial Setup Required screen: current password, new username and new password
    Initial Setup Required screen: current password, new username and new password

Until this step is done, the server refuses every other API request. That way nobody can take over a freshly installed instance with admin/admin before you do.

Worth setting up next

  • Settings → GeoIP: enter your MaxMind Account ID and MaxMind License Key to enable country blocking and country information in the logs. NPG downloads and updates the database.
  • Settings → SSL / ACME: put the address for certificate expiry notices in ACME Email.
  • My Account → Two-Factor Auth: turn on two-factor authentication for the admin account.

Changing ports

The nginx container runs in host network mode, so the ports entries in docker-compose.yml cannot change 80 and 443. If another program already uses 80 and 443, as on Synology, put these values in .env and restart.

NGINX_HTTP_PORT=8080
NGINX_HTTPS_PORT=8443

Your router then has to forward external ports 80 and 443 to 8080 and 8443 on the server, or Let's Encrypt HTTP-01 validation and outside access will not work.

Other port-related values:

VariableDefaultDescription
UI_PORT81Host port of the admin UI
API_HOST_PORT9080Loopback port nginx uses to reach the API. It must not clash with NGINX_HTTP_PORT.

The full list is in Environment variables.

Running without Valkey

Valkey is optional. With REDIS_URL= (empty) in .env, the API keeps its cache and rate-limit counters in its own memory. To drop the valkey service as well, also remove the valkey entry under the api service's depends_on in docker-compose.yml, or docker compose refuses to start.

Common problems

  • npg-proxy keeps restarting. Most likely another program holds port 80 or 443. Look for bind() ... failed in docker logs npg-proxy and follow "Changing ports" above.
  • The admin UI does not open. Make sure the address starts with https://. If docker compose ps shows npg-api still starting, wait a little.
  • The Docker container list in the proxy host form is empty. On Synology and similar systems the Docker API version may not be detected. Set DOCKER_API_VERSION (for example 1.41) in .env and restart.
  • Synology Container Manager shows no logs for the NPG containers. docker-compose.yml pins the log driver to json-file. docker logs still works. To see the logs in DSM, comment out each service's logging: block; log size limits then follow the Docker daemon's own settings.
  • You forgot the password. See Admin account recovery and 2FA.