# Random 502 bad gateway with php-fpm, why?

**URL:** <https://www.ruby-forum.com/t/random-502-bad-gateway-with-php-fpm-why/237467>\
**Category:** NGINX\
**Created:** [November 14, 2013, 7:13pm UTC](https://www.ruby-forum.com/t/random-502-bad-gateway-with-php-fpm-why/237467 "2013-11-14T19:13:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [November 14, 2013, 7:13pm UTC](https://www.ruby-forum.com/t/random-502-bad-gateway-with-php-fpm-why/237467/1 "2013-11-14T19:13:28Z")

</div>

My PHP application went down for a few hours with 502 bad gateway. In  
the  
nginx error log all I see is:

2013/11/14 10:02:16 [error] 1466#0: \*57964 recv() failed (104:  
Connection  
reset by peer) while reading response header from upstream

I fixed it by restarting php-fpm. However, what caused this? I don’t see  
anything interesting logged in the php-fpm or php logs. No indication of  
why  
happened, and why simply restarting php-fpm fixed the issue. I thought  
that  
php-fpm auto-restarted processes if they fail?

Any insights and place to determine the root cause? Thanks.

Posted at Nginx Forum:

> **[Random 502 bad gateway with php-fpm, why?](https://forum.nginx.org/read.php?2,244669,244669#msg-244669)**
>
> My PHP application went down for a few hours with 502 bad gateway. In the nginx error log all I see is: 2013/11/14 10:02:16 \[error\] 1466#0: \*57964 recv() failed (104: Connection reset by peer) while reading response header from upstream I fixed it by...

---

<div class="post-metadata">

**Author:** ![justin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@justin](https://www.ruby-forum.com/u/justin)\
**Post date:** [November 15, 2013, 11:55pm UTC](https://www.ruby-forum.com/t/random-502-bad-gateway-with-php-fpm-why/237467/2 "2013-11-15T23:55:36Z")

</div>

On Thu, Nov 14, 2013 at 01:13:08PM -0500, justin wrote:

> My PHP application went down for a few hours with 502 bad gateway. In the  
> nginx error log all I see is:
> 
> 2013/11/14 10:02:16 [error] 1466#0: \*57964 recv() failed (104: Connection  
> reset by peer) while reading response header from upstream

I recently hit the same problem and was able to ameliorate it by upping  
the OS limits (open files etc.). There are some discussions around this  
problem on stackoverflow and friends which suggest that one has to  
experiment.

Kind regards,  
–Toni++

---

<div class="post-metadata">

**Author:** ![justin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@justin](https://www.ruby-forum.com/u/justin)\
**Post date:** [November 15, 2013, 11:59pm UTC](https://www.ruby-forum.com/t/random-502-bad-gateway-with-php-fpm-why/237467/3 "2013-11-15T23:59:07Z")

</div>

Hey Tony.

Can you link to the stackoverflow posts? I wish php-fpm told me what  
happened.

Posted at Nginx Forum:

> **[Re: Random 502 bad gateway with php-fpm, why?](https://forum.nginx.org/read.php?2,244669,244724#msg-244724)**
>
> My PHP application went down for a few hours with 502 bad gateway. In the nginx error log all I see is: 2013/11/14 10:02:16 \[error\] 1466#0: \*57964 recv() failed (104: Connection reset by peer) while reading response header from upstream I fixed it by...

---

<div class="post-metadata">

**Author:** ![justin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/3ab097/32.png) [@justin](https://www.ruby-forum.com/u/justin)\
**Post date:** [November 16, 2013, 12:03am UTC](https://www.ruby-forum.com/t/random-502-bad-gateway-with-php-fpm-why/237467/4 "2013-11-16T00:03:47Z")

</div>

On Fri, Nov 15, 2013 at 05:58:41PM -0500, justin wrote:

> Can you link to the stackoverflow posts? I wish php-fpm told me what  
> happened.

See, my memory. =8-((

It was this link that helped me most:

> **[Configuring Nginx + PHP-FPM for Heavy Load](https://forum.nginx.org/read.php?11,215606,235395)**
>
> I was looking everywhere, but I could never find a good guide that explains how to configure Nginx with PHP-FPM for a heavy server load, so I hope this is the place where I will find my answer. I have a 24 core server with 32GB RAM with Centos 5.6...

Cheers,  
–Toni++
