使用proxy_pass时,可以使用/etc/hosts代替“resolver”来解析域名吗?

发布于 2024-12-18 14:58:02 字数 521 浏览 3 评论 0原文

使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

土豪我们做朋友吧 2024-12-25 14:58:02

您可以通过安装 dnsmasq 并将解析器设置为 127.0.0.1 来解决此问题。基本上,这使用您的本地 DNS 作为解析器,但它只解析它所知道的内容(其中包括您的 /etc/hosts)并将其余内容转发到您的默认 DNS。

You can get around this by installing dnsmasq and setting your resolver to 127.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.

清风不识月 2024-12-25 14:58:02

解决方法是使用 Nginx 映射,以便复制 /etc/hosts 内容。

map $wanted_host $wanted_host_ip
{
    default 127.0.0.1;
    b.dev.local X.X.X.X;
    a.dev.local X.X.X.X;
}

server
{
    listen              80;
    server_name         ~^(?P<wanted_port>[0-9]+?)-(?P<wanted_host>.+?)\.HOSTNAME$;

    location /
    {
        proxy_pass http://$wanted_host_ip:$wanted_port;

    }
}

这会将 wanted_host 映射到 wanted_host_ip ,就像解析器一样。

A workaround is to use Nginx map, in order to copy the /etc/hosts content.

map $wanted_host $wanted_host_ip
{
    default 127.0.0.1;
    b.dev.local X.X.X.X;
    a.dev.local X.X.X.X;
}

server
{
    listen              80;
    server_name         ~^(?P<wanted_port>[0-9]+?)-(?P<wanted_host>.+?)\.HOSTNAME$;

    location /
    {
        proxy_pass http://$wanted_host_ip:$wanted_port;

    }
}

This will map wanted_hostto wanted_host_ip , like a resolver.

作死小能手 2024-12-25 14:58:02

就我自己的 Windows 开发和测试机器而言,我必须安装 technitium DNS 服务器。然后创建一个新区域 (example.com) 并为我的代理域的 TLD (@) 添加一条指向 127.0.0.1 的 A 记录。然后将配置文件中的nginx解析器指向默认的Windows系统域名(desktop-hmvl5656)。 注意:在我自己的默认安装中,technitium DNS 服务器还使用默认的 Windows 系统域名作为后端管理门户网站

location /example {
   resolver desktop-hmvl5656;
   proxy_pass http://example.com$request_uri;
}

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

location /example {
   resolver desktop-hmvl5656;
   proxy_pass http://example.com$request_uri;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文