upstream timed out (10060: A connection attempt failed because the connected party did not properly respond

时间:2023-03-08 17:52:18

openresty 错误日志报错内容:

// :: [error] #: * upstream timed out (: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 10.4.101.11, server: localhost, request: "GET /xxx.jsp HTTP/1.1", upstream: "http://[::1]:8080/xxx.jsp", host: "10.1.3.42", referrer: "http://10.1.3.42/xxxindex.jsp"
// :: [error] #: * upstream timed out (: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond) while connecting to upstream, client: 10.4.101.11, server: localhost, request: "GET /xxx.jsp HTTP/1.1", upstream: "http://[::1]:8080/xxx.jsp", host: "10.1.3.42", referrer: "http://10.1.3.42/xxxxxex.jsp"

nginx.conf配置如下:

    upstream tomcat {
server localhost: weight= max_fails=;
server localhost: weight= max_fails=;
server 10.1.3.43: weight= max_fails=;
ip_hash;
} upstream file_tomcat {
server localhost: weight= max_fails=;
server localhost: weight= max_fails=;
ip_hash;
}

报错信息中看到:

upstream: "http://[::1]:8080/xxx.jsp

显然是 localhost 使用了 IPV6 去访问,导致出现问题。

将 locaohost改成 127.0.0.1 即可:

    upstream tomcat {
server 127.0.0.1: weight= max_fails=;
server 127.0.0.1: weight= max_fails=;
server 10.1.3.43: weight= max_fails=;
ip_hash;
} upstream file_tomcat {
server 127.0.0.1: weight= max_fails=;
server 127.0.0.1: weight= max_fails=;
ip_hash;
}