Nginx reports 502 error, log connect() failed (111: Connection refused) while connecting to upstream. A personal effective solution

Personal information is for reference only. If it is not applicable to your project, please do not speak ill of it.
The project adopts the mode of separation between front and rear ends, in which the routing relationship is Nginx A, which exposes the host address to the outside world, and all requests for App go directly to NginxB through the server.
The routing relationship is as follows: mobile App→ request (for example: www.test.cn: 8072/xp-web /index.html) →Nginx A→Nginx B
The server configuration of Nginx A routing to Nginx B is as follows:

  server {
        listen       8090;
   #     listen       192.25.106.214:8090;
        server_name  192.25.106.214;
	location /xy-app-web {
            proxy_pass http://192.25.106.214:8090/xy-app-web;
            proxy_set_header Host $host:8090;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Via "nginx";
        }
        location/{
            root   html;
            index  index.html index.htm;
        }
    }

Suddenly I found that there was A problem with the project, and the access interface reported an error. After checking the logs of Nginx A, I found the following errors:

[Error] 20969#0: *1 Connect () failed (111: Connection union) while connecting to upstream, Client: 192.25.103.53, Server: 192.25.106.214, Request: “GET /xy-app-web/portfolio/piazza?rettype=appjson& E72 opstation = Y_IHADPLAZA_12222222222_e9dfdb288326f0371d091ea8bd64b2f55b7906ff77b68db98ae99bafe0cf9896_07AE3442-1-4346 – A58B – 6 ee511202f01_30901_3. 9.0.11 & amp; logintoken=b6459d2e-1e85-489a-94e9-57d2059cba69& userId=5d395883d13573b189da524ce1401834& timestamp=1548750589604& client=3& device=appweb& version=appweb& clientId=appweb& Sign = 8 e6cfc226dbcf7dbd01a68a987363427 HTTP/1.0 “, upstream: “http://192.25.106.214:8090/xy-app-web/portfolio/piazza?rettype=appjson& E72 opstation = Y_IHADPLAZA_12222222222_e9dfdb288326f0371d091ea8bd64b2f55b7906ff77b68db98ae99bafe0cf9896_07AE3442-1-4346 – A58B – 6 ee511202f01_30901_3. 9.0.11 & amp; logintoken=b6459d2e-1e85-489a-94e9-57d2059cba69& userId=5d395883d13573b189da524ce1401834& timestamp=1548750589604& client=3& device=appweb& version=appweb& clientId=appweb& sign=8E6CFC226DBCF7DBD01A68A987363427”, host: “www.xyzqts.cn:8072”, referrer: “http://www.test.cn:8072/app-web/index.html”

Internet search for half a day is what shit like plagiarized article, what PHP problems. Our project did not have PHP, and the reason why connect() failed (111:Connection refused) while connecting to upstream was that the establishment of network Connection failed, so we started to check the call link from the place where the error was reported. Here we found that port 8090 did not provide service from the network call link of Telent Nginx B, A server of Nginx A. The simple way to do this is telent.
The correct picture for Telnet should look like this:

The problem is obvious. Take a look at which service is providing port 8090, indicate that the service is abnormal, and see if the process is still there.

ps -ef|grep java

I found that at some point, xy-app-Web on port 8090 was gone.
We’re using SpringBoot here, so start it.

nohup  java -jar -Dlogging.path=./logs xy-app-web-0.0.2.jar --spring.profiles.active=test & 

Check the process again: ps-ef |grep Java finds xy-app-web for port 8090 already available. Call the phone App again and find the problem solved.

 

Read More: