# Nginx upstream prematurely closed connection

**URL:** <https://www.ruby-forum.com/t/nginx-upstream-prematurely-closed-connection/218370>\
**Category:** NGINX\
**Created:** [March 29, 2012, 5:52pm UTC](https://www.ruby-forum.com/t/nginx-upstream-prematurely-closed-connection/218370 "2012-03-29T17:52:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 29, 2012, 5:52pm UTC](https://www.ruby-forum.com/t/nginx-upstream-prematurely-closed-connection/218370/1 "2012-03-29T17:52:12Z")

</div>

Hello,  
I’m using nginx as a reverse proxy to handle static files with apache to  
handle dynamic file .php  
I’m receiving too many errors ( Bad Gateway 502 ) when i’m using  
vBulletin , joomla , wordpress in PHP Post or curl() inside php.  
I reviewed log i noticed this error is frequently appears:  
“upstream prematurely closed connection while reading response header  
from upstream”  
Nginx version: nginx/1.0.11Apache/2.2.22PHP 5.2.17  
Thanks

---

<div class="post-metadata">

**Author:** ![Ramy\_Allam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@Ramy\_Allam](https://www.ruby-forum.com/u/Ramy_Allam)\
**Post date:** [March 30, 2012, 2:02pm UTC](https://www.ruby-forum.com/t/nginx-upstream-prematurely-closed-connection/218370/2 "2012-03-30T14:02:11Z")

</div>

Hello!

On Thu, Mar 29, 2012 at 03:51:31PM +0000, Ramy Allam wrote:

> Hello,  
> I’m using nginx as a reverse proxy to handle static files with apache to handle  
> dynamic file .php  
> I’m receiving too many errors ( Bad Gateway 502 ) when i’m using vBulletin ,  
> joomla , wordpress in PHP Post or curl() inside php.  
> I reviewed log i noticed this error is frequently appears:  
> “upstream prematurely closed connection while reading response header from  
> upstream”  
> Nginx version: nginx/1.0.11Apache/2.2.22PHP 5.2.17  
> Thanks

Such messages usually appear due to upstream server crash and/or  
process termination due to some limits (memory, cpu, execution  
time…). Try looking into apache logs and/or system logs to see  
what happens.

Maxim D.

---

<div class="post-metadata">

**Author:** ![Ramy\_Allam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@Ramy\_Allam](https://www.ruby-forum.com/u/Ramy_Allam)\
**Post date:** [April 9, 2012, 3:35pm UTC](https://www.ruby-forum.com/t/nginx-upstream-prematurely-closed-connection/218370/3 "2012-04-09T15:35:39Z")

</div>

This is also proxy log, not the static content request log.

You should be sure you have enough resources in your backend server,  
like memory, connection…

2012/4/9 Tariq wali [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

---

<div class="post-metadata">

**Author:** ![Ramy\_Allam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/58956e/32.png) [@Ramy\_Allam](https://www.ruby-forum.com/u/Ramy_Allam)\
**Post date:** [April 9, 2012, 1:42pm UTC](https://www.ruby-forum.com/t/nginx-upstream-prematurely-closed-connection/218370/4 "2012-04-09T13:42:41Z")

</div>

Maxim,

I see the same error on few of our lamp servers and nginx serving static  
content .  
I have looked for clues in apache error logs and syslog messages but  
can’t establish a connection …

2012/03/21 00:00:01 [error] 569#0: \*10867863 upstream prematurely closed  
connection while reading response header from upstream, client:  
121.243.22.130, server: \_, request: “GET / HTTP/1.1”, upstream:  
“[http://127.0.0.1:8080/](http://127.0.0.1:8080/)”, host: “[servername.net](http://servername.net)”  
2012/03/22 00:00:01 [error] 568#0: \*10869967 upstream prematurely closed  
connection while reading response header from upstream, client:  
121.243.22.130, server: \_, request: “GET / HTTP/1.1”, upstream:  
“[http://127.0.0.1:8080/](http://127.0.0.1:8080/)”, host: “[servername.net](http://servername.net)”  
2012/03/23 00:00:01 [error] 569#0: \*10872221 upstream prematurely closed  
connection while reading response header from upstream, client:  
121.243.22.130, server: \_, request: “GET / HTTP/1.1”, upstream:  
“[http://127.0.0.1:8080/](http://127.0.0.1:8080/)”, host: “[servername.net](http://servername.net)”

I would appreciate a direction I can take this issue in …’

T
