簡體   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