DEV Community

konsongong
konsongong

Posted on Originally published at vpsfolio.pages.dev

Self-Host Nginx Proxy Manager with Docker: A Production Guide

This tutorial was written with AI assistance from the project's official documentation. Verification status is stated at the end of the article.

What Nginx Proxy Manager does and what it needs

Nginx Proxy Manager (NPM) is a Dockerized control panel for Nginx. It gives you a web UI to create proxy hosts, redirects, streams, and 404 hosts, and it handles Let's Encrypt certificates automatically. You don't need to write Nginx configs by hand, though advanced users can inject custom directives.

The official image is jc21/nginx-proxy-manager:2.17.0. It bundles Nginx, Node.js, and the admin UI. The project does not publish a minimum RAM figure. Idle memory is modest, but memory use scales with the number of proxy hosts, active connections, and certificate renewals. Plan for at least 512 MB to be safe, and more if you're proxying high-traffic services.

NPM needs two persistent directories: /data for the SQLite database (or JWT keys if you use MySQL/Postgres) and /etc/letsencrypt for certificates. It listens on ports 80 (HTTP), 443 (HTTPS), and 81 (admin UI).

Prerequisites, ports, and volume constraints

  • A Linux VPS with Docker Engine 24+ and Docker Compose v2.
  • Ports 80 and 443 must be free. If you already run a web server on the host, stop it first.
  • Port 81 is the admin UI. Bind it to 127.0.0.1 so it's not exposed to the internet without TLS.
  • Two named volumes: npm_data and npm_letsencrypt. The official docs use bind mounts (./data, ./letsencrypt), but named volumes are cleaner for backups and avoid permission issues.
  • A database. The official docs support SQLite, MariaDB, and Postgres. This guide uses MariaDB for better concurrency and easier backups.

Create the project directory and generate secrets:

mkdir -p ~/npm && cd ~/npm
openssl rand -hex 32  # DB_PASSWORD
openssl rand -hex 32  # DB_ROOT_PASSWORD
Enter fullscreen mode Exit fullscreen mode

Production Docker Compose setup

Write the Compose file. It uses MariaDB, named volumes, and binds the admin port to localhost.

cat <<'EOF' > compose.yml
services:
  app:
    image: 'jc21/nginx-proxy-manager:2.17.0'
    restart: unless-stopped
    ports:
      - '80:80'
      - '443:443'
      - '127.0.0.1:81:81'
    environment:
      TZ: ${TZ:-UTC}
      DB_MYSQL_HOST: 'db'
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: 'npm'
      DB_MYSQL_PASSWORD: ${DB_PASSWORD}
      DB_MYSQL_NAME: 'npm'
      DISABLE_IPV6: ${DISABLE_IPV6:-false}
    volumes:
      - npm_data:/data
      - npm_letsencrypt:/etc/letsencrypt
    depends_on:
      - db

  db:
    image: 'linuxserver/mariadb:latest'
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASSWORD}
      MYSQL_DATABASE: 'npm'
      MYSQL_USER: 'npm'
      MYSQL_PASSWORD: ${DB_PASSWORD}
      TZ: ${TZ:-UTC}
    volumes:
      - npm_db:/config

volumes:
  npm_data:
  npm_letsencrypt:
  npm_db:
EOF
Enter fullscreen mode Exit fullscreen mode

Create the .env file with the secrets you generated:

cat <<'EOF' > .env
TZ=UTC
DB_PASSWORD=your_generated_password_here
DB_ROOT_PASSWORD=your_generated_root_password_here
DISABLE_IPV6=false
EOF
Enter fullscreen mode Exit fullscreen mode

Start the stack:

docker compose up -d
Enter fullscreen mode Exit fullscreen mode

Wait a minute for the database to initialize and JWT keys to generate. Then open http://127.0.0.1:81 in your browser. The default login is admin@example.com / changeme. Change it immediately.

Reverse proxy, HTTPS, and first-run hardening

NPM itself is a reverse proxy, so you don't need another one in front of it. But the admin UI on port 81 is HTTP-only. To secure it, create a proxy host in NPM that points to 127.0.0.1:81 and enable SSL with Let's Encrypt. Use a subdomain like npm.yourdomain.com.

Steps:

  1. Point npm.yourdomain.com to your server's IP.
  2. In NPM, go to Hosts → Proxy Hosts → Add Proxy Host.
  3. Domain: npm.yourdomain.com. Forward Hostname: 127.0.0.1. Forward Port: 81.
  4. Enable Block Common Exploits and Websockets Support.
  5. In the SSL tab, select Request a new SSL Certificate, agree to the ToS, and enable Force SSL.

Now the admin UI is available at https://npm.yourdomain.com. You can remove the 127.0.0.1:81:81 port mapping from Compose if you want to force all access through HTTPS.

First-run hardening:

  • Change the default admin password immediately.
  • Create a dedicated admin user and delete the default one.
  • Enable two-factor authentication if you have an authenticator app.
  • Restrict access to the admin UI by IP using an Access List in NPM.
  • Keep port 81 bound to localhost. Never expose it publicly without TLS.

If you're testing without a domain, use an SSH tunnel: ssh -L 81:127.0.0.1:81 user@your-server. Then open http://localhost:81.

Updating, backups, and common pitfalls

Update NPM and MariaDB:

cd ~/npm
docker compose pull
docker compose up -d
Enter fullscreen mode Exit fullscreen mode

Back up the volumes. Stop the stack first to ensure consistency:

docker compose stop
docker run --rm -v npm_data:/data -v $(pwd):/backup alpine tar czf /backup/npm_data.tar.gz -C /data .
docker run --rm -v npm_letsencrypt:/etc/letsencrypt -v $(pwd):/backup alpine tar czf /backup/npm_letsencrypt.tar.gz -C /etc/letsencrypt .
docker run --rm -v npm_db:/config -v $(pwd):/backup alpine tar czf /backup/npm_db.tar.gz -C /config .
docker compose start
Enter fullscreen mode Exit fullscreen mode

Restore by reversing the commands.

Common pitfalls:

  1. Port conflicts. If another service uses port 80 or 443, NPM will fail to start. Stop the conflicting service or change the host port mapping (e.g., 8080:80), but then Let's Encrypt HTTP validation will fail unless you adjust the challenge.
  2. Database connection issues. If you change DB_PASSWORD in .env after the database is initialized, NPM won't connect. Either keep the password stable or update it in MariaDB manually.
  3. Certificate renewal failures. Let's Encrypt requires port 80 to be reachable from the internet. If you're behind a firewall or CDN, use DNS challenge instead.
  4. IPv6 problems. If your host doesn't support IPv6, set DISABLE_IPV6=true in .env to avoid Nginx startup errors.

Monitor logs with docker compose logs -f app to catch issues early.


Measured in our sandbox run: total memory 246.2 MB (sum of per-container peaks over a 30s idle window after startup) across 2 containers; largest container 152.7 MB; published port(s) 80, 81, 443; HTTP probe returned 200, 200, 400. The run took 152.0s including the image download. Required secret(s) DB_PASSWORD, DB_ROOT_PASSWORD were generated for the test run, as the tutorial instructs. Container breakdown: app 152.7 MB, db 93.5 MB.


Verification: we ran this docker-compose stack in a disposable Docker environment and recorded the measurements above. They describe that run, not a guarantee for your host.


Originally published with full interactive benchmark metrics and server sizing notes at https://vpsfolio.pages.dev/self-host-nginx-proxy-manager-docker/.

Top comments (0)