Will nginx return 502 without any log in certain case?
mdounin at mdounin.ru
Mon Sep 10 11:56:59 UTC 2018
On Fri, Sep 07, 2018 at 06:44:58AM -0400, Fumitaka Yanase wrote:
> I have my nginx running on EC2(Amazon Linux) behind ALB (Load Balancer of
> Usually it works just fine but very rarely ALB receive 502 bad gateway form
> the EC2 instance.
> I checked both access.log and error.log of nginx but there is no log for 502
> bad gateway.
> We asked AWS about the reason of 502, but they told us it should be problem
> of web server running on EC2 instance.
> After some googling, I found an article that when nginx sends TCP RST or TCP
> FIN, it will return 502 without any log output.
> So I'm suggesting I am facing this case, but it there any way to figure out
> whether it is so or not?
> And if so, is there any way to get some information about why TCP RST or TCP
> FIN is caused?
If a HTTP response with status code 502 is returned by nginx, it
a) logs a message explaining the problem to the error log at the
"error" level and b) logs the request and the response status to
the access log.
If, however, a 502 error is generated by AWS load balancer, the
exact reason for the error is only known on the AWS load balancer
side. Depending on what exactly happened, there may be something
in nginx logs (not necessary an error) or nothing at all (for
example, if the load balancer wasn't able to connect to nginx).
If you want to further debug this, first of all you may want to
find out where the errors you are seeing are generated.
More information about the nginx