Docker 网络 Nginx 解析器 [英] Docker Network Nginx Resolver

查看:22
本文介绍了Docker 网络 Nginx 解析器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的配置中删除已弃用的 Docker 链接.剩下的就是在我重新创建容器时摆脱那些 Bad Gateway nginx 反向代理错误.

I am trying to get rid of deprecated Docker links in my configuration. What's left is getting rid of those Bad Gateway nginx reverse proxy errors when I recreated a container.

注意:我在桥接模式下使用 Docker 网络.(docker network create nettest)

Note: I am using Docker networks in bridge mode. (docker network create nettest)

我在 nginx 中使用以下配置片段:

I am using the following configuration snippet inside nginx:

location / {
      resolver 127.0.0.1 valid=30s;
      set $backend "http://confluence:8090";
      proxy_pass $backend;

  1. 我在我的 Docker 网络上启动了一个主机名为 confluence 的容器,名为 nettest.
  2. 然后我在网络 nettest 上启动了 nginx 容器.
  3. 我可以从 nginx 容器内部 ping confluence
  4. confluence 列在 nginx 容器的 /etc/hosts 文件中
  5. nginx 日志显示 send() 失败(111:连接被拒绝)而解析,解析器:127.0.0.1:53
  6. 我尝试了来自 /etc/resol.conf
  7. 的 docker 网络默认 dns 解析器 127.0.0.11
  8. nginx 日志显示 confluence 无法解析 (3: Host not found)
  1. I started a container with hostname confluence on my Docker network with name nettest.
  2. Then I started the nginx container on network nettest.
  3. I can ping confluence from inside the nginx container
  4. confluence is listed inside the nginx container's /etc/hosts file
  5. nginx log says send() failed (111: Connection refused) while resolving, resolver: 127.0.0.1:53
  6. I tried the docker network default dns resolver 127.0.0.11 from /etc/resol.conf
  7. nginx log says confluence could not be resolved (3: Host not found)

有人知道如何使用 Docker 网络配置 nginx 解析器,或者知道如何强制 Nginx 正确解析 Docker 网络主机名的替代方法吗?

Anybody knows how to configure nginx resolver with Docker Networks or an alternative on how to force Nginx to correctly resolve the Docker network hostname?

推荐答案

首先,您应该使用位于 127.0.0.11 的 Docker 嵌入式 DNS 服务器.

First off, you should be using the Docker embedded DNS server at 127.0.0.11.

您的问题可能是由以下原因之一引起的:

Your problem could be caused by 1 of the following:

  1. nginx 正在尝试使用 IPv6(AAAA 记录)进行 DNS 查询.

  1. nginx is trying to use IPv6 (AAAA record) for the DNS queries.

有关解决方案,请参阅https://stackoverflow.com/a/35516395/1529493.

See https://stackoverflow.com/a/35516395/1529493 for the solution.

基本上是这样的:

http {
    resolver 127.0.0.11 ipv6=off;
}

这可能不再是 Docker 1.11 的问题了:

This is probably no longer a problem with Docker 1.11:

修复不将 docker 域 IPv6 查询转发到外部服务器(#21396)

Fix to not forward docker domain IPv6 queries to external servers (#21396)

  • 注意不要意外覆盖resolver 配置指令.在我的情况下,我在 serverresolver 8.8.8.8 8.8.4.4; 中有来自 Mozilla 的 SSL 配置生成器,它覆盖了 httpresolver 127.0.0.11;> 阻止.这让我挠了很长时间...

  • Take care that you don't accidentally override the resolver configuration directive. In my case I had in the server block resolver 8.8.8.8 8.8.4.4; from Mozilla's SSL Configuration Generator, which was overriding the resolver 127.0.0.11; in the http block. That had me scratching my head for a long time...

    这篇关于Docker 网络 Nginx 解析器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆