Nginx 解决 "no resolver defined to resolve" 错误
Nginx 解决 "no resolver defined to resolve" 错误
在 Nginx 0.6.18 以后的版本中,如果 proxy_pass 使用了变量来构造地址,会报错:
no resolver defined to resolve
原因是 Nginx 要求使用变量时必须通过 resolver 指令指定 DNS 服务器。
解决方法
在 http{} 块或 location{} 块中添加:
location /api/ {
resolver 8.8.8.8;
proxy_pass http://backend.example.com$request_uri;
}
也可以使用其他 DNS 服务器,比如 114.114.114.114 或自建的 DNS。