nginx报错:connect() failed (111: Connection refused) while connecting to upstream

nginx错误日志有如下报错:
2021/06/21 14:24:47 [error] 12112#0: *7807990 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xx.xx.xx, server: localhost, request: “GET /itms/cpe/cpe.listPage.action HTTP/1.1”, upstream: “http://[::1]:xxxx/itms/cpe/cpe.listPage.action”, host: “xx.xx.xx.xx:xxxx”, referrer: “http://xx.xx.xx.xx:xxxx/itms/index.menu.action”

我这里是nginx配置有问题,针对这种情况,解决方式如下:

ifconfig 查看 lo
nginx报错:connect() failed (111: Connection refused) while connecting to upstream_第1张图片
::1 指的是本地ipv6地址

查看nginx配置
vim /usr/local/nginx/conf/nginx.conf
proxy_pass 中,如果配置的是localhost,就是转发到本地ipv4和ipv6,即报文章开头的错误。
nginx报错:connect() failed (111: Connection refused) while connecting to upstream_第2张图片
改成127.0.0.1,不再有报错
nginx报错:connect() failed (111: Connection refused) while connecting to upstream_第3张图片
改完重启nginx,
/usr/local/nginx/sbin/nginx -s reload

完毕。

你可能感兴趣的:(http,nginx,linux,centos)