Website shows 502 Bad Gateway: no resolver defined to resolve example.com

Created:

2016-11-16 12:39:53 UTC

Modified:

2017-04-22 18:56:30 UTC

1

Was this article helpful?


Have more questions?

Submit a request

Website shows 502 Bad Gateway: no resolver defined to resolve example.com

Symptoms

Website opens with the 502 Bad Gateway error.

The following error can be observed in the /var/log/nginx/error.log :

[error] 20109#0: *945 no resolver defined to resolve example.com, client: 192.168.0.1, server: , request: "GET / HTTP/1.1", host: "example.com"

The $host is used in the /etc/nginx/plesk.conf.d/server.conf under the location instead of server IP-address:

location / {
proxy_pass http://$host:7080; <--default is proxy_pass http://10.10.10.10:7080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Cause

Nginx misconfiguration, there is no resolver specified in the Nginx configuration.

Resolution

In order to make configuration with $host option to work resolver should be added to /etc/nginx/nginx.conf under the http section:

# grep -C2 resolver  /etc/nginx/nginx.conf
http {
resolver 127.0.0.1;
include mime.types;
default_type application/octet-stream;
Have more questions? Submit a request
Please sign in to leave a comment.