Installing Nginx Proxy Manager with Docker and Docker Compose

The Nginx Proxy Manager is a simple and efficient solution for managing reverse proxies. It offers an easy-to-use interface with integrated support for SSL certificates via Let’s Encrypt. Using Docker makes the installation process even simpler and can be completed in just a few steps.

In this article, you will learn how to install the Nginx Proxy Manager using Docker and Docker Compose, along with configuring the default access credentials for the management panel.

Requirements:

Before starting, make sure you have the following items installed and configured on your server:

  • Docker: For creating containers. You can follow our guides in Installing Docker on Windows and Install Docker on MacOS.
  • Docker Compose: To simplify configuration and execution of the Nginx Proxy Manager.
  • A Linux server (such as Ubuntu or Debian), which is compatible with other distributions.

Configuração do Docker Compose

Nota: This example will use the directory /data to create containers.

1. Create docker-compose.yml file

Create a new directory /data/nginx-proxy-manager for your project and navigate into it:

mkdir /data
cd /data
mkdir nginx-proxy-manager
cd nginx-proxy-manager

2. Create directories for persistence data

To ensure that the Nginx Proxy Manager’s data is persistent (not lost after container restarts), create the necessary directories:

mkdir -p /data/nginx-proxy-manager/data
mkdir -p /data/nginx-proxy-manager/letsencrypt
mkdir -p /data/nginx-proxy-manager/mysql/data/mysql

3. Create installation and configuration files

Create a file docker-compose.yml with the following content:

version: '3'
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    environment:
      DB_MYSQL_HOST: "[DB HOST]"
      DB_MYSQL_PORT: [DB PORT]
      DB_MYSQL_USER: "[DB USER]"
      DB_MYSQL_PASSWORD: "[DB USER PASSWORD]"
      DB_MYSQL_NAME: "[DB NAME]"
    volumes:
      - [LOCAL DATA DIRECTORY]:/data
      - [LOCAL LET'sENCRYPT DIRECTORY]:/etc/letsencrypt
  db:
    image: 'jc21/mariadb-aria:latest'
    environment:
      MYSQL_ROOT_PASSWORD: '[DB ROOT PASSWORD]'
      MYSQL_DATABASE: '[DB NAME]'
      MYSQL_USER: '[DB USER]'
      MYSQL_PASSWORD: '[DB USER PASSWORD]'
    volumes:
      - [LOCAL MYSQL DATA DIRECTORY]:/var/lib/mysql

Now change the following content:

[DB HOST] – The name of the MariaDB host.

[DB PORT] – The port of MariaDB server.

[DB ROOT PASSWORD] – MariaDB root password (make it a secure password).

[DB USER] – MariaDB user name.

[DB USER PASSWORD] – MariaDB user password.

[DB NAME] – MariaDB database for Nginx Proxy Manager.

[LOCAL DATA DIRECTORY] – The data directory for Nginx Proxy Manager on local system.

[LOCAL LET’sENCRYPT DIRECTORY] – The Let’sEncrypt directory for Nginx Proxy Manager on local system.

[LOCAL MYSQL DATA DIRECTORY] – The MariaDB data directory on local system.

Here is an example of a docker-compose.yml with all elements:

version: '3'
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    environment:
      DB_MYSQL_HOST: "db"
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: "admin_npm"
      DB_MYSQL_PASSWORD: "twRFDXm8kiu"
      DB_MYSQL_NAME: "npm_db"
    volumes:
      - /data/nginxproxymanager/data:/data
      - /data/nginxproxymanager/letsencrypt:/etc/letsencrypt
  db:
    image: 'jc21/mariadb-aria:latest'
    environment:
      MYSQL_ROOT_PASSWORD: 'nDBkJw1ccslHg'
      MYSQL_DATABASE: 'npm_db'
      MYSQL_USER: 'admin_npm'
      MYSQL_PASSWORD: 'twRFDXm8kiu'
    volumes:
      - /data/nginxproxymanager/mysql/data/mysql:/var/lib/mysql

Note that it is recommended to store sensitive data like passwords in a separate file or environment variable for security reasons.

Starting Nginx Proxy Manager

With the docker-compose.yml file configured and directories created, start the Nginx Proxy Manager:

docker-compose up -d

The -d flag ensures that containers are run in the background.

Accessing Administration Panel

After the containers have started, access the management panel of the Nginx Proxy Manager by visiting your server’s IP address and port 81:

http://[IP_DO_SERVIDOR]:81

Standard Credentials

Default credentials:

  • Username: admin@example.com
  • Password: changeme (Please change it immediately after the first login for security reasons.)

Configure Nginx Proxy Manager

After logging in to the management panel, you can start configuring your reverse proxies for internal services. Some of the features include:

  • Configuring reverse proxies: Easily direct your domains to internal services.
  • Automated SSL certificates via Let’s Encrypt
  • Creating additional administrators