Fix nginx: no resolver defined to resolve (variable proxy_pass)
A variable in proxy_pass makes nginx resolve names per request. Fix no resolver defined and the 502 with a resolver line or an upstream block.
2026/10/27 01:04:31 [error] 11#11: *1 no resolver defined to resolve backend.example.com, client: 127.0.0.1, server: , request: "GET /api/ HTTP/1.1", host: "127.0.0.1:8080"The proxy_pass address contains a variable ($backend), so nginx has to resolve the name when the request arrives, and no DNS server (resolver) is configured to ask. The client gets a 502. Add a resolver line, or make the variable point at an upstream block name.
Without a variable, proxy_pass http://backend.example.com:3000; is resolved once at startup (and startup fails if it cannot be resolved — see [5]). With a variable, the docs say the name "is searched among the described server groups, and, if not found, is determined using a resolver".
[1] Match it with the 502 in access.log at the same moment. nginx -t passes, so a config test does not catch this.
127.0.0.1 - - [27/Oct/2026:01:04:31 +0000] "GET /api/ HTTP/1.1" 502 157 "-" "curl/8.14.1" "-"[2] Pick the fix by why the variable is there.
| Why the variable is used | Fix |
|---|---|
| follow backend IP changes without restarting nginx (containers, cloud load balancers) | add a resolver → [3] |
| choose a backend by path or header | make an upstream block per backend and put its name in the variable → [4] |
| no particular reason | drop the variable and write the address; startup fails if the name cannot be resolved → [5] |
[3] Set a resolver in the server or http block. valid overrides the TTL of the answer for caching.
server { listen 80; resolver 192.0.2.53 valid=30s; resolver_timeout 5s; location /api/ { set $backend "backend.example.com"; proxy_pass http://$backend:3000; }}Take the DNS server address from the nameserver line in the server's /etc/resolv.conf. If that server does not answer, the error changes as below (the test used 127.0.0.1, where no DNS server runs). Once "no resolver" turns into "could not be resolved", look at the DNS side (address, firewall, name).
2026/10/27 01:04:34 [error] 26#26: send() failed (111: Connection refused) while resolving, resolver: 127.0.0.1:532026/10/27 01:04:36 [error] 26#26: *1 backend.example.com could not be resolved (110: Operation timed out), client: 127.0.0.1, server: , request: "GET /api/ HTTP/1.1", host: "127.0.0.1:8080"[4] If the variable only chooses a backend, put an upstream name in it. When the name matches a server group, no resolver is used. In the test the same request went straight to connecting to the backend without no resolver (connection refused, because no backend was running).
upstream backend_pool { server 127.0.0.1:3000;}server { listen 80; location /api/ { set $backend "backend_pool"; proxy_pass http://$backend; }}2026/10/27 01:04:39 [error] 42#42: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: , request: "GET /api/ HTTP/1.1", upstream: "http://127.0.0.1:3000/api/", host: "127.0.0.1:8080"[5] Without the variable the name is resolved at startup, and an unknown name now stops the config test.
nginx: [emerg] host not found in upstream "backend.example.com" in /etc/nginx/conf.d/default.conf:5nginx: configuration file /etc/nginx/nginx.conf test failedWhichever fix you use, run nginx -t && systemctl reload nginx, send one request to that path and check that no new line of the same error appears. Other 502 causes are in Tell the cause of an Nginx 502 Bad Gateway from error.log.
Analyze your Nginx log in the browser ↗ — nothing is uploaded.