Setting Up NGINX Proxy Manager for Docker Containers
Aron Schüler Published
Intro
In the world of containerized applications, managing network connections securely and efficiently can become challenging, especially when you need multiple services accessible from a single endpoint. To do this, you need a reverse proxy that can route requests to the appropriate containers based on the incoming URL. I used to do this with NGINX manually, but handling all proxy headers for various services and optimizing is a task that I don’t find much joy in, especially when it comes to debugging weird redirect loops.
This is where NGINX Proxy Manager can be incredibly useful. NGINX Proxy Manager offers a nice GUI to quickly set up a proxy without a single line of code. This guide walks you through setting up a reverse proxy with NGINX Proxy Manager to manage access to Docker-hosted applications effectively.
Step-by-Step Guide
Step 1: Set Up a virtual network for your applications
For NGINX to route requests to your containers, it needs to be part of the same Docker network. Let’s create an external network, named proxied, which both the proxy and the containers you want to proxy will join.
Run the following command to create this network:
docker network create proxied
Step 2: Create the proxy service with Docker Compose and NGINX Proxy Manager
Next, we’ll set up NGINX Proxy Manager to handle the routing. Here’s a docker-compose.yml configuration that runs NGINX Proxy Manager in the created network:
In this setup:
• Port 80 is used for HTTP requests.
• Port 443 is for HTTPS.
• Port 81 provides access to the NGINX Proxy Manager’s admin interface, where you can manage proxy hosts, SSL certificates, and settings.
Save the file, then run:
docker-compose up -d
Step 3: Configure a Docker Container to Be Proxied
Now, we’ll set up a Docker container to be accessible through the NGINX Reverse Proxy. For this example, we’ll use a simple WordPress setup:
By adding the container to the same proxied network, it becomes accessible to the NGINX Reverse Proxy.
Step 4: Add the Proxy Host in NGINX Proxy Manager
Access the NGINX Proxy Manager’s admin interface at http://localhost:81. Once logged in:
- Click Add Proxy Host.
- Under Details:
- Set the Scheme to http.
- For Forward Hostname/IP, use the container_name of the proxied container (serviceA_wp in our example).
- Forward Port should be set to 80 (default port for HTTP).
- Under SSL:
- If you have DNS records pointing to this NGINX instance, you can request a new SSL certificate.
- Alternatively, add an existing certificate if you have one ready.
Step 5: Test everything!
Once configured, navigate to the domain you associated with the proxy. You should be able to access the proxied service directly through the NGINX Reverse Proxy. If this does not work, work your way top down: Is the host it self accessible? Is NGINX Reverse Proxy accessible? You can disable the host and NGINX Reverse Proxy should give you a “Congratulations, this is NGINX Reverse Proxy!” page.
Conclusion
Setting up an NGINX Reverse Proxy for Docker containers allows you to manage your applications efficiently and securely through a single endpoint. With this approach, you can simplify access to multiple services, add SSL certificates to secure connections, and centralize network configuration.
Feel free to share your questions or experiences with similar setups in the comments below. Happy proxying!