When Nginx Proxy Manager shows a 502 Bad Gateway, the fault is almost never in NPM itself. NPM answered you and then could not get a usable reply from the app behind it. These are the causes I check first, and a checklist to run in order.
- Time
- 14 min
- Steps
- 10
- Updated
- 27 Nov 2026
You will learn
- What do you need before you start?
- What does a 502 from NPM actually te…
- Is the forward hostname wrong?
- Is the scheme http or https?
- Are NPM and the app on the same Dock…
A 502 Bad Gateway from Nginx Proxy Manager sounds like a problem with NPM, and it almost never is. The page means that NPM answered you, then tried to talk to the app behind it and got nothing usable back. So the fault sits between NPM and the app: the wrong address, the wrong protocol, or a network the two containers do not share. I run NPM on my Unraid server in front of several containers, and the same three causes explain nearly every 502 I have seen on forums and in my own setup.
This guide goes through them in the order I would check them, then ends with a fixed checklist you can run top to bottom. I have written about parts of this setup before: the NPM review, a Nextcloud behind NPM guide and a tip on putting NPM on a Docker network. I do not repeat those here.
Step 1 of 10: What do you need before you start?
You need NPM running in Docker, at least one proxy host that shows the 502, and a terminal on the machine that runs Docker. On Unraid the web terminal is enough. You also need the name of the app container and the port the app listens on inside the container. If you do not know that port, look it up in the app’s own documentation. The port in your docker-compose.yml or in the Unraid template is often the published one on the host side, which is a different number.
Nothing below changes your data. The few steps that do change something, like moving a container to another network, say so first.
Step 2 of 10: What does a 502 from NPM actually tell you?
NPM is a front end for nginx. When nginx cannot get an answer from the upstream, the app you proxy to, it returns 502. Nginx has a few ways to reach that state. The connection is refused because nothing listens on that address and port. The name does not resolve, so nginx never gets as far as connecting. The connection opens but the two sides do not agree on the protocol, so the handshake fails. Or the app accepts the connection and closes it without a valid reply, often because it has just crashed.

That list explains why the page is so vague. Every one of those cases looks the same in the browser. The log tells them apart, and I come to it in the checklist. First the three causes that cover most cases.
Step 3 of 10: Is the forward hostname wrong?
The proxy host form has a field called Forward Hostname / IP. This is where most 502s start. Three mistakes show up again and again.

In this example the scheme is http, the hostname is the container name portainer and the port is 9000, the combination the NPM docs use.
The first is localhost or 127.0.0.1. Inside the NPM container, localhost is the NPM container itself. Nothing on port 3000 or 8080 is listening there, so you get a 502. The docs give an example of the same idea from the other side: the app is reached by its service name, for example portainer, and not by an address of the Docker host.
The second is the name of the container that NPM cannot resolve. A hostname only works when both containers share a user-defined Docker network. On Docker’s default bridge network, containers cannot find each other by name. That comes from Docker, not from NPM, and I wrote it up as a tip: containers find each other by name on a custom Docker network, not on the default bridge.
The third is the wrong IP address. People enter the address of the machine, or an old address of the container, and the container later gets another one. A container IP that Docker hands out is not stable. If you want to use an IP, use the fixed address of the host together with the published port. If you want to use a name, use the container name on a shared network.
To test the address without guessing, run a throwaway container on the same network as the app and ask for the page:
docker run --rm --network <network> curlimages/curl -sv http://<container>:<port>/Replace the three placeholders. If that prints the app’s page or a redirect, the name, the port and the network are fine, and the problem is somewhere else in the proxy host. If it says it could not resolve the host, or that the connection was refused, you have found it. I use a separate container for this because I cannot promise that curl exists inside the NPM image.
Step 4 of 10: Is the scheme http or https?
The proxy host form has a Scheme setting next to the hostname and port. It describes how NPM talks to the app, and it has nothing to do with how visitors reach NPM. Visitors use the SSL tab and your certificate. NPM then talks to the app over the scheme you choose here.
Most self-hosted apps listen on plain HTTP inside the container. They need http. A few apps only speak HTTPS on their own port. Examples are tools with a built-in self-signed certificate, which often use a separate HTTPS port. For those you need https. Mix them up and nginx tries to start a TLS handshake against a plain HTTP port, or sends plain HTTP to a TLS port. The handshake fails, and the visitor sees a 502 or sometimes a 400 page.
Two rules help. First, check what the app documents for its default port: if it names an HTTP port and an HTTPS port, you pick the scheme that matches the port in the Forward Port field. Second, do not choose https just because you want a padlock in the browser. The padlock comes from the certificate on the NPM side, and it works fine with an http upstream on a private Docker network.
If the app really needs https with a self-signed certificate, NPM does not need to verify that certificate. That is a setting of nginx on the proxy side, and which options the NPM form offers differs per version, so check the form of your version before you rely on a forum answer.
Step 5 of 10: Are NPM and the app on the same Docker network?
This is the cause I would suspect when the hostname looks right. Two containers can both be running and still not see each other, because they sit on different networks. NPM can only use a container name when both are on the same user-defined network.

The NPM docs describe the usual setup. Create one custom network, then add it to the compose file of NPM and of each app as the default network. In the docs’ example the network is called scoobydoo:
docker network create scoobydoonetworks:
default:
external: true
name: scoobydooWith that in place you create the proxy host with the service name as the hostname and the port the app exposes inside the container. The docs use portainer and port 9000. You do not need to publish that port on the host. The docs also note that the service name is the hostname, so service names must be unique on the same network.
People trip over this when they switch from an IP address to a name. The forward port is the port inside the container. If your compose file says 8080:80, the app listens on 80 in the container. Over a shared network you enter 80. You enter 8080 only if you go through the host address.
To see which networks a container is on:
docker inspect --format '{{json .NetworkSettings.Networks}}' <container>Compare the network names in the output for NPM and for the app. If they share none, that is your 502. Connecting a running container to a network is one command and does not recreate it:
docker network connect <network> <container>A connection made this way is lost when the container is recreated, so also put the network in the compose file or the template. On Unraid, the container’s Network Type field in the template does the same. If your user-defined networks disappear after a Docker restart, see my tip on Preserve user defined networks.
Step 6 of 10: What if the hostname, scheme and network all look right?
Then the app itself may be the problem. A 502 also appears when the app has crashed, is still starting or listens only on the loopback address. Look at the container before you change anything else:
docker ps -a --filter name=<container>
docker logs --tail 50 <container>A container that is restarting, or that exited, explains the 502 on its own. Fix that first. An app that needs a minute to start, like a media server or a database-backed app, returns 502 for that minute after every restart, and that is normal.
An app on the host rather than in a container is a separate case. If it listens on 127.0.0.1 only, a container cannot reach it, however correct the address is. The app needs to listen on an address the container can reach, and the host firewall must allow the port. Be careful when you open that up: an app bound to all interfaces is reachable from the whole network, so check what it exposes first.
The last cause I would look for is a stale address. After you recreate the app container, NPM may still try the old one. Reloading NPM often clears that, and restarting the NPM container does as well. This is common advice from user reports and not something I found in the docs, so I treat it as a last step and not a first one. There is also a tip about the resolver setting that touches this area.
One more thing that sends people in circles: the page can come from somewhere else. If the 502 page carries the Cloudflare name, the error comes from Cloudflare and not from NPM, and the cause is the connection between Cloudflare and your NPM. If it only says nginx, it came from NPM.
Step 7 of 10: What does a 502 look like in the log?
Recent versions of NPM have a Logs page in the top menu. I am on 2.17.1. Pick the proxy host in the first dropdown, then switch between Access and Error. If your version has no Logs page, the same files sit in the data volume, as step six of the checklist describes.
In the access log each line starts with the date, followed by two status codes. The first is what nginx recorded for the app behind it, the second is what it sent to the browser. A line with 502 502 is the one you are looking for.

The Error tab says why. This is from my own server, a proxy host in front of Beszel, where an agent tries to connect every ten seconds:
2026/11/27 04:04:55 [error] connect() failed (111: Connection refused) while connecting to upstream,
client: <ip>, server: <domain>, request: "GET /api/beszel/agent-connect HTTP/1.1",
upstream: "http://<ip>:<port>/api/beszel/agent-connect"

Two parts of that line are worth reading. Connection refused means that the address answered and nothing was listening on that port. The upstream part shows the exact address and port NPM tried, which is where a typo or an old IP shows up.
In my log these errors sit in a window of a minute and a half or less around 04:05, on two nights in a row, and the same host answers with 200 later in the day. The proxy settings are not the first suspect in a case like that. A time that repeats is worth holding next to your backup and update schedules.

Step 8 of 10: Is it a 502 or a 504?
A 504 Gateway Timeout is a different fault. NPM tried the app and gave up waiting, and the error log then says upstream timed out. Check how long the app takes to answer before you change hostnames and networks.
Step 9 of 10: What is the fixed checklist?
Run these in order and stop at the first step that fails. Each one is cheap, and the order goes from the most common cause to the least.
- Open the proxy host in NPM and read the Forward Hostname / IP, the port and the scheme out loud. No
localhost, no127.0.0.1, and the port is the one inside the container when both are on a shared network. - Check that the app container is running with
docker ps, and readdocker logs --tail 50for a crash loop or a startup that is still going on. - Check the networks of both containers with
docker inspect. They must share a user-defined network when you use a name. - Run the throwaway curl container on that network and ask for the app’s page. A page or a redirect means the upstream is fine.
- Compare the scheme with the port. An HTTP port needs http, an HTTPS port needs https.
- Read the NPM error log for that proxy host. Each host has its own log files, named after the host number, in the logs folder of the data volume.
docker exec <npm> ls /data/logslists them. On a version with a Logs page you can read the same thing in the browser. The error log names the upstream address that failed and the reason: connection refused, no route, a failed handshake or a name that did not resolve. - Only now reload or restart NPM, and recreate the app container if it still has an old address.
The log is the most useful step, and it sits at number six only because the earlier steps are quicker. If you cannot tell which cause you have, jump to it directly, because the reason in that one line settles it. “Connection refused” points at the port, the bind address or a stopped app. A name that does not resolve points at the network or a typo. A handshake error points at the scheme.
Step 10 of 10: How do you check that it is fixed, and how does it break again?
Open the site in a private window so that no cached page confuses you, and reload it twice. Then restart the app container and load the page again after a minute. If the page still loads after a restart, NPM is reaching the app by name and not by an address that happened to be right.
It breaks again in a few predictable ways. A container recreated outside the compose file loses a network you attached by hand. An app update changes the port the app listens on, which changes what you enter in the Forward Port field. A new app copied from an example uses the default bridge, so it works by IP on your test and fails by name in the proxy host. And two services with the same name on one network answer in turn, which looks like a random 502.
If you set up a new proxy host in a hurry, do the network and name check first and the SSL tab after.
From the Netherlands there is one practical extra. If you reach your server through a provider that puts you behind CGNAT, the 502 you see from outside may come from the path to your NPM and not from the app behind it. Test from inside your own network first, so you know which half is broken.
Further reading
- Nginx Proxy Manager docs: Advanced configuration (best practice: use a Docker network)
- Nginx Proxy Manager docs: Setup
- Nginx Proxy Manager docs: FAQ
- Nginx Proxy Manager review
- Tip: put Nginx Proxy Manager on a Docker network and stop publishing ports
- Tip: containers find each other by name on a custom Docker network
