nginx解析代理传递上的localhost

uttx8gqw  于 7个月前  发布在  Nginx
关注(0)|答案(1)|浏览(95)

我有一个服务器,只响应localhost.我不能改变这一点.我已经提交了两张票与微软.作为权宜之计,我下载了nginx的Windows.这曾经工作,但由于某种原因,它停止工作.
我认为这个问题是因为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>
 ...

x

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>

的一种或多种

eyh26e7m

eyh26e7m1#

502 -表示upstream/backend没有响应,如果backend关闭,这是nginx的正常响应。
curl 127.0.0.1:5000为例:

Failed to connect to 127.0.0.1 port 5000

字符串
检查你的后端应用程序在5000/tcp端口。可能是这个应用程序没有绑定在localhost IP / 5000/tcp端口,或者没有运行。
Netstat for windows cmd:

netstat -np TCP | findstr 5000

相关问题