繁体   English   中英

nginx 在代理通行证上解析 localhost

[英]nginx resolving localhost on proxy pass

我有一个只响应本地主机的服务器。 我无法改变这一点。 我已经向 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>

502 - 表示您的上游/后端没有响应,如果后端关闭,是 nginx 的正常响应。

在你的例子中curl 127.0.0.1:5000

Failed to connect to 127.0.0.1 port 5000

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

windows cmd 的网络统计:

netstat -np TCP | findstr 5000

暂无
暂无

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

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