Tag Archives: Nginx error 111

Nginx error 111: connection rejected [How to Solve]

Recently, I encountered nginx crazy throwing errors. There are more than 5W entries in access.log a day, but there are about 9K entries in error.log, which are basically 111: connection rejected . Why

From the log

Let’s look at the log first. I extracted a log of errors thrown in the error.log (divide it into one line slightly, otherwise it is too long, and handle the sensitive information slightly):

2019/06/06 10:09:45 [error] 28652#0: *883239 connect() failed (111: Connection refused) while connecting to upstream, 
client: 124.104.90.145, server: xxx.xxxxx.com, request: "POST /test-service/upload?mcachenum=155978698 HTTP/1.1", 
upstream: "http://[::1]:17000/test-service/upload?mcachenum=155978698", host: "xxx.xxxxx.com", 
referrer: "https://servicewechat.com/x98b46f69/2/page-frame.html"

After looking at the error report in front and the description in the back, it seems normal at first glance. But after looking again, I found that the host in upstream is somewhat different [:: 1] , which is actually an IPv6 address

 

At this time, you can check whether your machine has IPv6 address enabled. The command of Linux is: IP address , and see if inet6 appears in the returned result. If so, congratulations. The reason has been found

Solution

There are two solutions. One is to disable the IPv6 configuration of your machine, and the other is to modify the configuration in nginx.conf

Personally, I think the latter method is safer because it does not involve your machine configuration and should be relatively least

The modification of nginx.conf is to modify proxy for location in the server module_The host in pass , which we often see on the Internet, is:

proxy_pass http://localhost:18000/test -service/;

However, in order to forcibly specify the IPv4 address, it needs to become:

proxy_pass http://127.0.0.1:18000/test -service/;

 

After this operation, observe the error.log of nginx, and there should be no more IPv6 address errors in upstream

Summary

The above is the whole process of my mistake. Although the whole process is not long, it does let me know that as a back-end development, my knowledge is still too narrow. And Bing is really easy to use. I can’t climb the wall recently. It’s good to use Bing instead for the time being