proxy host upstream `host.docker.internal` cannot be resolved when `extra_hosts` is used (variable `proxy_pass` + resolver path)
Summary
When Nginx Proxy Manager is deployed with Docker Compose and extra_hosts defines host.docker.internal, proxy host validation can still fail with:
host.docker.internal could not be resolved (3: Host not found)
This happens even though the hostname is present in the container's /etc/hosts.
Version
- Reproduced on:
v2.13.7 - The upstream resolution path appears unchanged in newer templates.
Environment
- Docker Compose deployment
extra_hostsconfigured for NPM container, e.g.:host.docker.internal:host-gateway(or an explicit host IP)
Steps to Reproduce
- Deploy NPM with
extra_hostscontaininghost.docker.internal. - Create a Proxy Host with:
- Forward Hostname/IP:
host.docker.internal - Forward Port:
<your service port>
- Forward Hostname/IP:
- Save/apply the host config.
Actual Behavior
NPM/Nginx config test fails with:
host.docker.internal could not be resolved (3: Host not found)
Expected Behavior
If host.docker.internal is available via system resolver path (/etc/hosts), the proxy host should be accepted and work.
Why this happens
NPM proxy templates use variable-based proxy_pass (e.g. $server), which relies on Nginx runtime DNS resolver behavior. That resolver does not use /etc/hosts, so extra_hosts entries are not honored in this path.
Proposed Fix (backward-compatible)
Add an optional NPM-side pre-resolution step (disabled by default), for example:
- New env flag:
NPM_PRE_RESOLVE_UPSTREAM_HOSTS=true - During config generation:
- pre-resolve eligible upstream hostnames via system resolver (
dns.lookup) - write resolved IP into generated upstream target
- if resolution fails, keep original hostname
- pre-resolve eligible upstream hostnames via system resolver (
This preserves current default behavior while providing a compatible path for Docker setups relying on extra_hosts.
Notes
I can open a PR with implementation and docs updates. Default behavior remains unchanged unless the new env flag is enabled.
The root cause: when NPM uses variable-based proxy_pass (e.g. $server), nginx resolves that hostname through its configured DNS resolver (127.0.0.11 — Docker's embedded DNS). That resolver is pure DNS and explicitly ignores /etc/hosts, so anything added via extra_hosts is invisible to nginx at proxy time.
Three workarounds until the proposed env flag lands:
1. Same-network services — if you're proxying to another container, put it on the same Docker network as NPM and use the service name directly (http://my-service:8080). Docker's embedded DNS resolves service names correctly.
2. Use host-gateway instead of a static IP:
extra_hosts:
- "host.docker.internal:host-gateway"
Docker resolves host-gateway to the host's actual gateway IP at container start (typically 172.17.0.1 on Linux). Still hits the /etc/hosts limitation with variable proxy_pass, so combine with option 3 below.
3. Static upstream via Custom Nginx Configuration — in NPM's proxy host → "Custom Nginx Configuration" tab, bypass the variable resolver entirely:
proxy_pass http://172.17.0.1:PORT;
Replace 172.17.0.1 with your host's docker0 IP: ip addr show docker0 | grep 'inet '. Not portable across machines but works reliably without waiting on the env flag.
The NPM_PRE_RESOLVE_UPSTREAM_HOSTS approach in the issue description is the right permanent fix — pre-resolving at config generation time uses the system resolver (which does read /etc/hosts) and writes the IP statically into the nginx config.
Issue is now considered stale. If you want to keep it open, please comment :+1:
Not stale