nginx.ccWeb server troubleshooting desk
Home / Errors / 502
502

nginx: no resolver defined to resolve — causes and fix

Short answer

When proxy_pass contains a variable (proxy_pass https://$host, $backend…), the name is resolved per request, and nginx does not read /etc/resolv.conf: you must name DNS servers with resolver. Without it nginx logs “no resolver defined” and returns 502. Add resolver, or use an upstream / a variable-free proxy_pass.

Most common cause: proxy_pass contains a variable and no resolver is configured.

Try this first: Set a resolver

http {
    resolver 1.1.1.1 8.8.8.8 valid=300s ipv6=off;
    resolver_timeout 5s;
}

Last verified: · against the official docs listed below · Sources

Typical log lines

no resolver defined to resolve api.example.com, client: 203.0.113.7
api.example.com could not be resolved (3: Host not found)

Common causes

  1. proxy_pass contains a variable and no resolver is configured.
  2. Proxying to a Docker service name needs Docker's embedded DNS at 127.0.0.11.
  3. resolver points at 127.0.0.53 (systemd-resolved), which does not exist inside a container.

Diagnosis commands

Confirm the error
#grep -E 'no resolver|could not be resolved' /var/log/nginx/error.log | tail -3
Which proxy_pass lines use variables
#nginx -T 2>/dev/null | grep -nE 'resolver|proxy_pass .*\$'
The system DNS (nginx does not read it)
#grep nameserver /etc/resolv.conf

Fix configs

Set a resolver

http {
    resolver 1.1.1.1 8.8.8.8 valid=300s ipv6=off;
    resolver_timeout 5s;
}

Inside Docker

resolver 127.0.0.11 valid=30s;   # Docker's embedded DNS
set $backend http://app:3000;
proxy_pass $backend;

No dynamic resolution needed: drop the variable

upstream api {
    server api.example.com:443;
}
proxy_pass https://api;   # resolved once at startup

Run nginx -t first, then systemctl reload nginx.

Key facts and sources

  • When the proxy_pass address contains variables, the name is resolved at run time and needs a resolver (unless it matches a defined upstream). [nginx.org]
  • resolver caches answers for their TTL by default; the valid parameter overrides it. [nginx.org]

Checked against the linked pages on 2026-11-14; the official docs win if a newer nginx changes them.

FAQ

Why is no resolver needed without variables?

Without variables nginx resolves the name at startup and reload with the system resolver; the catch is that IP changes need a reload.

What does valid=300s do?

It overrides the record's TTL and caches answers for 300 seconds.

Fix it with a tool

Related errors

Sponsored slot (empty)
VPS / CDN recommendations may appear here later, labelled as affiliate links. There are no referral links today.