使用proxy_pass时,可以使用/etc/hosts代替“resolver”来解析域名吗?
使用proxy_pass时可以使用/etc/hosts代替resolver吗?
我需要对同一台 nginx 机器执行 proxy_pass 。有没有办法使用计算机的 /etc/hosts 文件来解析域,而不是通过“解析器”属性指定 DNS 服务器?
这将为我节省到达同一服务器所需的额外跃点。我尝试在 /etc/hosts 文件中设置映射到 DNS 的内部 IP,但 nginx 仍在从 resolver 属性中设置的 DNS 服务器读取数据。或者有没有办法让 HTTPProxy 模块考虑 /etc/hosts 文件设置?
感谢您可以分享的任何建议。
这与我在 nginx 论坛中发布的问题相同: http://forum.nginx.org/read.php?11,218997
Can /etc/hosts be used instead of resolver when using proxy_pass?
I need to perform a proxy_pass to the same nginx machine. Is there a way to resolve the domains using the machine's /etc/hosts file instead of specifying a DNS server thru the "resolver" property?
This will save me the additional hops needed to reach the same server. I have tried setting up the internal IP mapped to the DNS in /etc/hosts file but nginx is still reading from the DNS server set in the resolver property. Or is there a way to make the HTTPProxy module to consider the /etc/hosts file settings?
Thanks for any advice you could share..
This is the same question I posted in the nginx forum:
http://forum.nginx.org/read.php?11,218997
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过安装
dnsmasq
并将解析器设置为127.0.0.1
来解决此问题。基本上,这使用您的本地 DNS 作为解析器,但它只解析它所知道的内容(其中包括您的/etc/hosts
)并将其余内容转发到您的默认 DNS。You can get around this by installing
dnsmasq
and setting your resolver to127.0.0.1
. Basically this uses your local DNS as a resolver, but it only resolves what it knows about (among those things is your/etc/hosts
) and forwards the rest to your default DNS.解决方法是使用 Nginx 映射,以便复制
/etc/hosts
内容。这会将
wanted_host
映射到wanted_host_ip
,就像解析器一样。A workaround is to use Nginx map, in order to copy the
/etc/hosts
content.This will map
wanted_host
towanted_host_ip
, like a resolver.就我自己的 Windows 开发和测试机器而言,我必须安装 technitium DNS 服务器。然后创建一个新区域 (example.com) 并为我的代理域的 TLD (@) 添加一条指向 127.0.0.1 的 A 记录。然后将配置文件中的nginx解析器指向默认的Windows系统域名(desktop-hmvl5656)。 注意:在我自己的默认安装中,technitium DNS 服务器还使用默认的 Windows 系统域名作为后端管理门户网站
In my own case on my Windows development and testing machine, I had to install technitium DNS server. Then created a new zone (example.com) and added an A record for my proxy domain's TLD (@) pointing to 127.0.0.1. Then pointed the nginx resolver in the config file to the default Windows system's domain name (desktop-hmvl5656). Note: In my own default installation the technitium DNS server also used the default Windows system domain name for the backend management webportal