【问题标题】:proxy_pass does not resolve DNS using /etc/hostsproxy_pass 不使用 /etc/hosts 解析 DNS
【发布时间】:2015-07-10 22:21:56
【问题描述】:

在 nginx 中,proxy_pass 指令未使用 /etc/hosts 文件解析 DNS。有什么方法可以实现这种可能性(也许通过使用 Lua 作为最后的手段)?

【问题讨论】:

    标签: nginx lua dns hosts hosts-file


    【解决方案1】:

    简而言之,你需要在本地安装dnsmasq,并使用127.0.0.1作为解析器。

    查看此相关问题和答案:

    When using proxy_pass, can /etc/hosts be used to resolve domain names instead of "resolver"?

    【讨论】:

      【解决方案2】:

      如果您有一个带有 systemd 的服务器,您可以使用它附带的名称服务器 systemd-resolved 从 /etc/hosts 文件中解析您的主机名。

      只需将其添加到您的 nginx 配置 httpserverlocation 块:

      resolver 127.0.0.53;
      

      使用systemctl status systemd-resolved.service 查看它是否在您的服务器上运行。

      【讨论】:

        猜你喜欢
        • 2017-03-14
        • 2021-12-02
        • 2012-01-08
        • 2019-09-24
        • 1970-01-01
        • 2012-11-16
        • 1970-01-01
        • 1970-01-01
        • 2021-10-26
        相关资源
        最近更新 更多