繁体   English   中英

Nginx给502错误的网关时如何调试?

[英]Howto debug when nginx gives 502 bad gateway?

landing.example.com:10000上,我有一个运行良好的Web服务器,它是一个暴露端口10000的Docker容器。 它的IP是172.17.0.2

我想要在端口80上具有nginx反向代理,然后根据访问者访问的URL将访问者发送到不同的Docker容器。

server {
    listen 80;
    server_name landing.example.com;

    location / {
        proxy_pass http://172.17.0.2:10000/;
    }

    access_log /landing-access.log;
    error_log  /landing-error.log info;
}

当我这样做时,我得到502 Bad Gateway ,日志显示

2016/04/14 16:58:16 [error] 413#413: *84 connect()
failed (111: Connection refused) while connecting to upstream, client:
xxx.xxx.xxx.xxx, server: landing.example.com, request: "GET / HTTP/1.1",
upstream: "http://172.17.0.2:10000/", host: "landing.example.com"

尝试这个:

upstream my_server {
   server 172.17.0.2:10000;
}

server {
   listen 80;
   server_name landing.example.com;
   location / {
      proxy_pass                  http://my_server;
      proxy_set_header            Host $host;
      proxy_set_header            X-Real-IP $remote_addr;
      proxy_http_version          1.1;
      proxy_set_header            X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header            X-Forwarded-Proto http;
      proxy_redirect              http:// $scheme://;
   }
}

在这里,您可以定义上游服务器(按IP或主机名的服务器),并确保也转发标头,以便服务器回答已知的答案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM