- Ansible beginner tutorial - Wed, Nov 15 2023
- Nested Docker containers: Run Docker in a Docker container - Fri, Nov 10 2023
- Docker networking: Connect a Docker container - Fri, Oct 27 2023
In addition, the tool has an elegant interface based on Tabler that makes the configuration process user-friendly and fun. The open-source system was designed to make it easier for users to manage reverse proxying hosts with SSL termination.
NPM supports various features and carries several benefits that make it a top choice. In addition, it integrates with several platforms.
In this post, I will show you how to set up Nginx Proxy Manager with Docker on Ubuntu 22.04.
Prerequisites
- Ubuntu 22.04 as your initial operating environment
- A non-root user with sudo privileges
- Docker Engine and Docker Compose packages are installed and running
- A valid domain name for Nginx Proxy Manager (npm.linuxbuz.com in this tutorial).
Verifying Docker and Docker Compose installation
Since we are going to install Nginx Proxy Manager with Docker, we must have the latest version of Docker and Docker Compose installed. First, enter the following command in your command line interface to verify the Docker installation:
docker --version
If Docker is already installed, you should get something like:
Docker version 20.10.16, build aa7e414
To verify the Docker Compose installation, run the command below:
docker-compose version
If Docker Compose is already installed, you should get something like:
Docker Compose version v2.6.0
Creating a Docker Compose configuration file
Docker Compose uses a docker-compose.yml file to define the service definitions for setting up an application inside the container. Docker Compose allows users to define multiple services for multi-container applications and link them with shared networks.
Let's start by creating a directory for Nginx Proxy Manager. For this tutorial, we will create an nginx-proxy directory. Type the following command to create a directory and navigate into it:
mkdir ~/nginx-proxy cd ~/nginx-proxy
Next, create a directory to hold Let's Encrypt SSL and database:
mkdir data mkdir ssl
Next, let's create a docker-compose.yml file to define different services to deploy Nginx Proxy Manager:
nano docker-compose.yml
Add the following configurations to the file to define all required services:
version: "3" services: app: image: 'jc21/nginx-proxy-manager:latest' restart: unless-stopped ports: # These ports are in format <host-port>:<container-port> - '80:80' # Public HTTP Port - '443:443' # Public HTTPS Port - '81:81' # Admin Web Port environment: DB_MYSQL_HOST: "db" DB_MYSQL_PORT: 3306 DB_MYSQL_USER: "npm" DB_MYSQL_PASSWORD: "npm" DB_MYSQL_NAME: "npm" volumes: - ./data:/data - ./ssl:/etc/letsencrypt - ./config.json:/app/config/production.json depends_on: - db db: image: 'jc21/mariadb-aria:latest' restart: unless-stopped environment: MYSQL_ROOT_PASSWORD: 'npm' MYSQL_DATABASE: 'npm' MYSQL_USER: 'npm' MYSQL_PASSWORD: 'npm' volumes: - ./data/mysql:/var/lib/mysql
Here's a brief explanation of each service definition:
- The first line in a file is the version definition line. You can define your preferred version in this line.
- app: Defines the service definition name of the Nginx Proxy Manager.
- image: Specifies the name of the Nginx Proxy Manager and MariaDB image.
- restart: Specifies the restart behavior of the container.
- ports: Specifies the port numbers on which you want to expose your application.
- environment: Specifies the environment variables that hold the database credentials.
- volumes: Defines the mount locations for MySQL data, Let's Encrypt SSL, and the config.json file on the container. Volumes allow us to share application code and data with other containers.
- depends_on: Specifies the dependent container. In this case, the app container depends on the db container.
- db: Provides the service definition name of the database.
Defining environment variables
Environment variables are very important for communications between the Nginx Proxy Manager container and the database container. Environment variables hold the database host, name, password, and port information.
In this tutorial, we define the database credentials in the config.json file. Let's create a config.json file inside the nginx-proxy directory:
nano config.json
Add the following configurations:
{ "database": { "engine": "mysql", "host": "db", "name": "npm", "user": "npm", "password": "npm", "port": 3306 } }
When you finish, save and close the file.
Starting the container
Docker Compose allows us to start all the services we specified in the docker-compose.yml file with just one command: docker-compose up.
Let's start all the containers and make them run in the background using the -d flag:
docker-compose up -d
You should see the following output after starting up all the containers:
[+] Running 3/3 ⠿ Network nginx-proxy_proxy-internal Created 0.1s ⠿ Container proxy-db Started 1.3s ⠿ Container proxy-app Started 1.3s
To verify the status of all running containers, run the docker-compose ps command:
docker-compose ps
You should see the list of all running containers in the following output:
nginx-proxy-app-1 "/init" app running 0.0.0.0:80-81->80-81/tcp, 0.0.0.0:443->443/tcp, :::80-81->80-81/tcp, :::443->443/tcp nginx-proxy-db-1 "/scripts/run.sh" db running 3306/tcp
If something goes wrong, you can check the logs for each container using the docker logs command and specify the service name. For example, to check the log of the Nginx Proxy Manager container, run the following command:
docker logs nginx-proxy-app-1
Setting up Nginx Proxy Manager
At this point, Nginx Proxy Manager is installed and running on ports 80 and 81. Now, open your web browser, and access the URL http://your-server-ip to verify the Nginx Proxy Manager. If everything is okay, you should see the Nginx Proxy Manager default page:
Next, access the Nginx Proxy Manager admin interface using the URL http://your-server-ip:81 in your web browser. You will be redirected to the Nginx Proxy Manager sign-in page:
Provide the following default credentials to log in:
Email address: admin@exampl.com
Password: changeme
Then, click the Sign in button. Once you have logged in successfully, you should see the user setup screen:
Change your default username and email, and click Save. You should see the password reset screen:
Showing the password reset screen
Change your default password, and click Save. You should see the Nginx Proxy Manager dashboard screen:
Configuring domain name and SSL
At this point, Nginx Proxy Manager is configured with a public IP address. We recommend setting a domain for accessing Nginx Proxy Manager.
On the Nginx Proxy Manager dashboard, click Hosts > Proxy Hosts to open the Proxy Hosts:
After that, click the Add Proxy Host button to create a new proxy host, as shown below:
Define your domain name, public IP, and port, and click the SSL tab:
Under SSL Certificate, select Request a new SSL Certificate. Then enable Force SSL and HTTP/2 Support and click Save. You will see your added proxy hosts on the following screen:
You can now access the Nginx Proxy Manager using your domain name https://npm.linuxbuz.com/.
Conclusion
In this tutorial, I demonstrated how to set up Nginx Proxy Manager with Docker on Ubuntu 22.04. You can now start using the Nginx Proxy Manager to add a proxy host for another Docker container.
Read the latest IT news and community updates!
Join our IT community and read articles without ads!
Do you want to write for 4sysops? We are looking for new authors.
“Bad gateway” when trying to login to NGINX Proxy Manager using admin@exampl.com / changeme. Cannot proceed.
You can use admin@example.com as username and changeme as a password to login
I also have bad gateway when putting example credentials.
Were doing copy and paste only.
This solution worked for me:
“Check that you don’t have the mysql folder nested inside the data folder.
So in your docker-compose file you need to define the volumes as follows:
npm:
volumes:- ./data:/data
…
db:
volumes:
– ./mysql:/var/lib/mysql (NOT: ./data/mysql:/var/lib/mysql)”
https://www.reddit.com/r/nginxproxymanager/comments/12ilet7/bad_gateway_on_nginxproxymanager_running_in_docker/
Did change the docker-compose file to ./mysql:/var/lib/mysql under db volumes:.
The error persists.
I noted that your had volumes:- ./data:/data under npm: The script has that under app: Could that be an issue?
This is the fix od docker-config files :
Thanks. The fix got me in the door. I did get as far as pulling a cert from Let’s Encrypt, but ended up with ERR_TOO_MANY_REDIRECTS when I tried to open the web page.
Solved it by putting the local IP of VW in the SSL tab vs the public IP.
Am in business!
Hello. I love you. Seriously. I spent the last several hours trying to figure out how to install an SSL certificate for my npm itself and did not realize that you needed to set it to http and forceSSL as I kept on using https when trying to setup the proxy host entry and would get a 502 Bad Gateway Error…. and then I found this post. Thank you so much.
Email or password not working. Please help.
restart the mariadb container. it was for me using portainer