nginx 在代理通道上解析本地主机

问题描述 投票:0回答:1

我有一个仅响应本地主机的服务器。我无法改变这一点。我已向 Microsoft 提交了两张票证。作为权宜之计,我下载了 Windows 版 nginx。这曾经有效,但由于某种原因它停止工作了。

我认为问题是因为 nginx 正在解析为 http://127.0.0.1。很明显,在大多数情况下它不会飞。我将其指向其他站点并且它可以工作,但如果我将其指向 example.org 并且它重定向到 http://1.1.1.1 example.org 可能无法配置为响应该情况。

http {

    server {
        listen       41281;
        
        location / {
                #proxy_set_header X-Real-IP $remote_addr;
                #proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                #proxy_set_header Host $host;
                #proxy_set_header X-NginX-Proxy true;
                proxy_pass http://localhost:5000/;
                #proxy_redirect http://localhost:5000/ http://$server_name/;
        }
    }

我已经尝试了注释掉的内容和现在的方式。

error.log 说:

2020/08/07 22:05:10 [error] 26908#22324: *1 connect() failed (10061: No connection could be made because the target machine actively refused it) while connecting to upstream, client: 192.168.0.29, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "192.168.0.29:41281"

浏览器/curl 得到 502。

$ curl localhost:5000
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3024  100  3024    0     0   246k      0 --:--:-- --:--:-- --:--:--  268k<DOCTYPE html>
<html>
<head>
 ...
jbaro@ezio MINGW64 ~
$ curl 127.0.0.1:5000
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
curl: (7) Failed to connect to 127.0.0.1 port 5000: Connection refused
jbaro@ezio MINGW64 ~
$ curl localhost:41281
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   157  100   157    0     0     71      0  0:00:02  0:00:02 --:--:--    71<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.19.0</center>
</body>
</html>
nginx nginx-reverse-proxy
1个回答
0
投票

502 - 意味着你的上游/后端没有响应,如果后端关闭,这是 nginx 的正常响应。

在您的示例中

curl 127.0.0.1:5000

Failed to connect to 127.0.0.1 port 5000

检查 5000/tcp 端口上的后端应用程序。可能是这个应用程序没有绑定在本地主机 IP / 5000/tcp 端口上,或者没有运行。

Windows cmd 的 Netstat:

netstat -np TCP | findstr 5000
© www.soinside.com 2019 - 2024. All rights reserved.