# Getting 502 bad gateway on uploading a file

**URL:** <https://www.ruby-forum.com/t/getting-502-bad-gateway-on-uploading-a-file/212730>\
**Category:** NGINX\
**Created:** [October 12, 2011, 3:02am UTC](https://www.ruby-forum.com/t/getting-502-bad-gateway-on-uploading-a-file/212730 "2011-10-12T03:02:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [October 12, 2011, 3:02am UTC](https://www.ruby-forum.com/t/getting-502-bad-gateway-on-uploading-a-file/212730/1 "2011-10-12T03:02:04Z")

</div>

Trying to upload a small .png to Drupal. PHP 5.3.8, CentOS 5.6 x64,  
nginx 1.1.3

Everything else seems to work fine, but can’t seem to get any deeper  
information as to why anything is getting messed up. Not sure if the  
debug log has any hints or not.

(note I also tried nginx 1.0.8) - does this debug log help with  
anything? or is this “probably PHP”?

[http://pastebin.com/E1kDBegW](http://pastebin.com/E1kDBegW)

Thanks

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 12, 2011, 1:29pm UTC](https://www.ruby-forum.com/t/getting-502-bad-gateway-on-uploading-a-file/212730/2 "2011-10-12T13:29:00Z")

</div>

Hello!

On Tue, Oct 11, 2011 at 06:01:46PM -0700, Michael S. wrote:

> Trying to upload a small .png to Drupal. PHP 5.3.8, CentOS 5.6 x64, nginx 1.1.3
> 
> Everything else seems to work fine, but can’t seem to get any deeper  
> information as to why anything is getting messed up. Not sure if the  
> debug log has any hints or not.
> 
> (note I also tried nginx 1.0.8) - does this debug log help with  
> anything? or is this “probably PHP”?
> 
> [http://pastebin.com/E1kDBegW](http://pastebin.com/E1kDBegW)

The “recv() failed (104: Connection reset by peer) while reading  
response header from upstream” message suggests PHP closed  
connection for some reason (died?) right after nginx sent request  
to it. Looking more closes on php side is a way to go.

Maxim D.

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 12, 2011, 1:39pm UTC](https://www.ruby-forum.com/t/getting-502-bad-gateway-on-uploading-a-file/212730/3 "2011-10-12T13:39:32Z")

</div>

if you are using php-fpm over fastcgi i would guess its due to fpm’s  
request\_terminate\_timeout because the upload took too long

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 12, 2011, 2:29pm UTC](https://www.ruby-forum.com/t/getting-502-bad-gateway-on-uploading-a-file/212730/4 "2011-10-12T14:29:32Z")

</div>

Hello!

On Wed, Oct 12, 2011 at 07:39:09PM +0800, Mauro Stettler wrote:

> if you are using php-fpm over fastcgi i would guess its due to fpm’s  
> request\_terminate\_timeout because the upload took too long

Very unlikely, as everything happens within 1 second.

2011/10/11 17:55:34 [debug] 2505#0: \*1 http request line: "POST …  
…  
2011/10/11 17:55:34 [error] 2505#0: \*1 recv() failed (104: Connection  
reset by peer) …

Maxim D.

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 12, 2011, 8:10pm UTC](https://www.ruby-forum.com/t/getting-502-bad-gateway-on-uploading-a-file/212730/5 "2011-10-12T20:10:44Z")

</div>

2011/10/12 Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > if you are using php-fpm over fastcgi i would guess its due to fpm’s  
> > request\_terminate\_timeout because the upload took too long
> 
> Very unlikely, as everything happens within 1 second.
> 
> 2011/10/11 17:55:34 [debug] 2505#0: \*1 http request line: "POST …  
> …  
> 2011/10/11 17:55:34 [error] 2505#0: \*1 recv() failed (104: Connection reset by  
> peer) …

Exactly - this happens _immediately_ like it doesn’t even try…

Alright well if the logs don’t give you any clue from the nginx side,  
I’ll have to try to figure out the PHP side now 🙂

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [October 12, 2011, 8:57pm UTC](https://www.ruby-forum.com/t/getting-502-bad-gateway-on-uploading-a-file/212730/6 "2011-10-12T20:57:49Z")

</div>

On 10/11/11 9:01 PM, Michael S. wrote:

> Trying to upload a small .png to Drupal. PHP 5.3.8, CentOS 5.6 x64, nginx 1.1.3

Is this only happening with png’s? Are you able to upload other types of  
files? If so, I have seen this type of behavior before. It has happened  
after PHP version upgrades. Darn near drove me crazy as I could never  
trace it. It resolved with recompiling of php and all modules, including  
pecl modules. Just a thought. YMMV, of course.

> Thanks
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–  
Jim O.
