浏览 3.9k
客户生产环境,架构为Nginx+haproxy,在请求时日志里有connect() failed (111: Connection refused) while connecting to upstream, client: xxxxxxx, server: localhost 信息。
此问题不知是否为网络网关配置导致的,希望有大神帮忙分析一下原因。
指向的页面是用vue写的。
nginx.conf 中的部分配置如下
location ^~ /busimod/ {
proxy_pass http://127.0.0.1:8101/;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
}
location ^~ / {
try_files $uri $uri/ @router;
index busiPage.html;
}
location @router {
rewrite ^.*$ /busiPage.html last;
}

按点赞数排序
按时间排序
导致502的一个常见原因,是三次握手建立失败了,你可以用netstat统计下,是否存在报文丢失等情况,如果是的话,报502就是正常的,此时你可以通过Nginx的next upstream机制,在Nginx层通过重新转发请求把502错误化解掉。
Nginx在匹配location之前,以下3步中都可能产生400错误码:
1、接收、解析URL和header时,请求格式错误会导致400错误;
2、preread阶段的HTTP模块产生的错误;
3、server_rewrite重定时出现的错误;
猜测你应当是出现了请求格式非法问题,此时URL不值得信任,因此location匹配也不会做,location {access_log xxx; }自然也不会生效。具体可以参考我的这篇文章:https://www.nginx-cn.net/article/69
网络延迟,负载均衡,连接池都可能会有这种问题,如果是连接池耗尽,新请求就有可能会堆积并等待处理,导致数据丢失和混乱,调整一下大小就可以,或者是某部分后端服务器负载较重,而其他比较轻,也会导致请求堆积和数据混乱。
微信公众号
加入微信群