个人技术分享

1.nginx反向代理

	# 测试
	server {
        listen       80;
        server_name  local.dongpeng.com;
		
        location / {
            # proxy_pass http://192.168.10.131:9394;
            proxy_pass http://127.0.0.1:9394;
        }
    }

2.出现异常

2024/05/01 17:53:41 [error] 6#6: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.10.1, server: local.dongpeng.com, request: "GET /sso/doLogin?name=sa&pwd=123456 HTTP/1.1", upstream: "http://127.0.0.1:9394/sso/doLogin?name=sa&pwd=123456", host: "local.dongpeng.com"

注意:  Connection refused  说明请求抵达nginx,但是nginx去proxy_pass地址连接失败,说明proxy_pass地址错误了。

<html>

<head>
    <title>502 Bad Gateway</title>
</head>

<body bgcolor="white">
    <center>
        <h1>502 Bad Gateway</h1>
    </center>
    <hr>
    <center>nginx/1.13.0</center>
</body>

</html>

3.解决

其实错误原因上面 已经说了,就是proxy_pass地址错误了,因为这里的nginx是用docker容器部署,当前127.0.0.1是当前容器,而不是对应本机的ip,将对应的127.0.0.1改为对应本机的ip,由nginx容器能够访问到的ip,就正常了。