Error 502 intermittent error (using nginx, nodejs, mongodb)

We use nodejs (v 0.10.29), express, nginx (version 1.4.6) with mongodb (v 2.6.3) replicaset and we get an intermittent error of the 502 gateway error. Pm2 logs cannot log error, although nginx aerror.log shows

recv() failed (104: Connection reset by peer) while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: somedomain.com, request: "GET /img/abc.png HTTP/1.1", upstream: "http://127.0.0.1:3000/img/abc.png", host: "domain.com", referrer: "http://domain.com/admin/" 

and access.log says:

 "GET /url/abc.html HTTP/1.1" 502 723 "http://domain.com/admin/" "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36" 

can someone help me with the problem?

+7
nginx express
source share
3 answers

This is probably not a problem with nginx per se, but a problem with nodejs. Error 502 “bad gateway” means that nginx requested some information from the nodejs server, and the nodejs server answered, and then “hung up quickly”. “Hang up” refers more to the message part “Connection reset via peer-to-peer connection”.

Now this may indicate a lot of different problems, so I can’t give a definitive answer.

Perhaps an error occurred while processing the request, which would require tracking the error through js code.

Could this be a memory issue (what does your memory usage look like)?

Or it could be a timeout error in the node part, because the response has been returning for too long either due to an error in the code or due to lack of memory.

I know that I used intermittent timeout errors between nginx and php-fpm because nginx refused to wait for php. I adjusted memory usage and timeout settings to fix this (and I optimized the PHP code).

If you can provide more specific information about memory usage / loading or logs from a node or application or even a common template with 502 errors (is it localized in a geographic region, browser, OS?), Then the answer may be less speculative.

+9
source share

This happened to me when connecting to the server. Node.js server filmed a Nginx package of 300-400 bullets, for example:

 get http://example.com/?a=1&b=2&c=3 

The second could not answer this in time and refused the word 502 .

The solution I came up with sent the request one by one in small pieces.

0
source share

In our case, nginx was on top of Node.js, which was automatically launched by Forever. Due to an error in the contents of the Redis database, the Node server crashed intermittently, and nginx returned either a 502 or a 503 error. It took us a while to find the reason, since Node only reported Forever error messages.

Thus, the source of the failure was not a failure in nginx or its configurations, the Node server (and its background services).

0
source share

All Articles