gpt4 book ai didi

Nginx + dnsmasq = 'could not be resolved (5: Operation refused)'

转载 作者:行者123 更新时间:2023-12-04 00:02:07 28 4
gpt4 key购买 nike

我正在尝试使用 docker、nginx 和 uwsgi 建立一个 django 站点:我有一个 nginx docker 容器作为反向代理(称为 ceca-nginx-proxy),其中 dnsmasq正在运行并且另一个与 uwsgi 容器 (ceca-uwsgi) 通信的 nginx (ceca-nginx) 容器,我可以使用 curl (带有 curl --resolve <a href="http://test.ceca.com" rel="noreferrer noopener nofollow">http://test.ceca.com</a> <a href="http://172.17.0.7" rel="noreferrer noopener nofollow">http://172.17.0.7</a> ) 连接到 ceca-nginx 容器,并且我让 django 站点在 ceca 中运行-uwsgi 容器,问题是当我想通过 ceca-nginx-proxy 获取站点时:我在 ceca-nginx-proxy 错误日志中收到此错误:

ceca-nginx could not be resolved (5: Operation refused), client: 172.17.0.1, server: *.ceca.com, request: "GET / HTTP/1.1", host: "172.17.0.8"

  • 172.17.0.1 是分配的 docker ip
  • *.ceca.com 是 ceca-nginx-proxy 的 nginx 配置中定义的 server_name
  • 172.17.0.8 是 ceca-nginx-proxy ip
  • ceca-nginx-proxy反向代理的server block 是:

    server {
    listen 80;
    server_name *.ceca.com;
    error_log /tmp/proxy_error_nginx.log warn;
    access_log /tmp/proxy_access_nginx.log;

    location / {
    set $example ceca-nginx;
    resolver 127.0.0.1;
    proxy_pass http://$example;
    }
    }

    我在同一台机器上运行 dnsmasq 来解析/etc/hosts 中的主机名(来自 docker 链接容器的主机名),如下所示:

    dnsmasq -q -8 /tmp/dnsmasq.log --port 53 -R -u root

    对于我在 dnsmasq.log 中看到的内容,主机名解析正常 [1] 但 nginx 提示并返回“502 Bad Gateway”页面。如果有人能帮我解决这个问题,我将永远感激不尽,如果我们相遇,我会买很多啤酒和蕨类植物。

    [1]

    Jun 6 21:39:47 dnsmasq[321]: query[A] ceca-nginx from 127.0.0.1
    Jun 6 21:39:48 dnsmasq[321]: /etc/hosts ceca-nginx is 172.17.0.7
    Jun 6 21:39:48 dnsmasq[321]: query[AAAA] ceca-nginx from 127.0.0.1

最佳答案

您的问题似乎与Nginx有关resolver指令配置。默认情况下,Nginx 将尝试解析 IPv4 和 IPV6 地址。它将从 DNS 服务器(在您的情况下为 dnsmasq)获取第一个响应,将其缓存并因异常 Operation denied 而失败,因为它无法将 DNS 名称解析为IPv6 地址。解决方案是将 ipv6=off 添加到您的 resolver 指令中,因此它应该如下所示:

...
resolver 127.0.0.1 ipv6=off;
...

这将强制 Nginx 停止将 DNS 记录解析为 IPv6。

关于Nginx + dnsmasq = 'could not be resolved (5: Operation refused)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37669403/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com