【问题标题】:docker nginx appear "502".1 upstream server temporarily disabled while connecting to upstreamdocker nginx 出现“502”.1 上游服务器在连接上游时暂时禁用
【发布时间】:2017-12-13 04:13:08
【问题描述】:

我在 docker 中使用 nginx,这是我的 nginx 配置

server {    listen  80;     server_name saber;

    location / {        
       root /usr/share/nginx;       
       index index.html;
}

    location /saber {       
        proxy_pass http://localhost:8080;   
        proxy_redirect off;     
        proxy_set_header Host $host;    
        proxy_set_header X-Real-IP $remote_addr;        
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        
        proxy_buffer_size 4k;       
        proxy_buffers 4 32k;        
        proxy_busy_buffers_size 64k;    
        proxy_connect_timeout 90;   
    }

}

当我在浏览器中使用“http://localhost/saber/blog/getBlog.do”时,浏览器给我一个错误“502”。 和 nginx 的 error.log 有新的。

2017/07/09 05:16:18 [warn] 5#5: *1 upstream server temporarily disabled while connecting to upstream, client: 172.17.0.1, server: saber, request: "GET /saber/blog/getBlog.do HTTP/1.1", upstream: "http://127.0.0.1:8080/saber/blog/getBlog.do", host: "localhost"

我可以保证“http://127.0.0.1:8080/saber/blog/getBlog.do”在浏览器中响应成功。 我尝试在其他问题中搜索答案,我发现答案是“/usr/sbin/setsebool httpd_can_network_connect true”,这是问题网址“nginx proxy server localhost permission denied”,但我在win10中使用docker,nginx容器dont hava setsebool,because the container dont找到 SELinux。 这一切,提前谢谢你。

【问题讨论】:

    标签: nginx docker


    【解决方案1】:

    每个容器(如 nginx 容器)内部的 localhost 与容器外部的 localhost 不同。默认情况下,每个容器都有自己的网络命名空间。您需要将容器放置在同一个 docker 网络(不是默认的桥接网络)上,而不是指向 localhost,并使用容器或服务名称与 Docker 的内置 DNS 进行连接。目标端口也将是容器端口,而不是您主机上的已发布端口。

    【讨论】:

    • 哦,我意识到问题的原因是网络。最后,我将“proxy_pass localhost:8080”中的 localhost 更改为“10.2.8.158”(这是我计算机中的 IPv4)。就是这样。谢谢。
    • 这会将你连接到 docker 之外,然后再返回。如果你在 docker 网络中运行东西,它们可以直接连接,容器到容器,这样更便携。
    • 我找到了解决方案here。可能对你有用:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-16
    • 2020-10-23
    • 1970-01-01
    相关资源
    最近更新 更多