# 502 errors and request\_time

**URL:** <https://www.ruby-forum.com/t/502-errors-and-request-time/243527>\
**Category:** NGINX\
**Created:** [December 2, 2015, 8:40am UTC](https://www.ruby-forum.com/t/502-errors-and-request-time/243527 "2015-12-02T08:40:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [December 2, 2015, 8:40am UTC](https://www.ruby-forum.com/t/502-errors-and-request-time/243527/1 "2015-12-02T08:40:24Z")

</div>

Hi:

I’ve found 2 kinds of 502 errors in my server:

connection reset by peer, it happens as request\_time reach to 10s.

connection timeout, it happens as request\_time reach to 3s.

Server is:

centos , kernel(2.6.32)

php5.2 php-fpm

nginx 1.6.3.

access logs outputs:  
[28/Nov/2015:14:41:08 +0800] “GET /ben2.php HTTP/1.1” 502 172 “-”  
“Apache-HttpClient/4.2.6 (java 1.5)” “-” 3.000

[28/Nov/2015:14:41:11 +0800] “GET /ben2.php HTTP/1.1” 502 172 “-”  
“Apache-HttpClient/4.2.6 (java 1.5)” “-” 10.000  
error logs:  
2015/11/28 14:41:11 [error] 12981#0: \*798323 recv() failed (104:  
Connection reset by peer) while reading response header from upstream,  
client: xx.xx.xx.xx, server: xx.xx.xx, request: “GET /ben2.php  
HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host: “xx.xx.xx”

2015/11/28 14:41:08 [error] 12981#0: \*798215 connect() failed (110:  
Connection timed out) while connecting to upstream, client: xx.xx.xx.xx,  
server: xx.xx.xx, request: “GET /ben2.php HTTP/1.1”, upstream:  
“fastcgi://127.0.0.1:9000”, host: “xx.xx.xx”

I’ve tried “request\_terminate\_timeout, fastcgi\_connect\_timeout,  
fastcgi\_read/write\_timeout”, but no help.

What can I do next step ?

---

<div class="post-metadata">

**Author:** ![Shi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f14d63/32.png) [@Shi](https://www.ruby-forum.com/u/Shi)\
**Post date:** [December 2, 2015, 8:40am UTC](https://www.ruby-forum.com/t/502-errors-and-request-time/243527/2 "2015-12-02T08:40:59Z")

</div>

Hello!

On Sat, Nov 28, 2015 at 03:02:33PM +0800, Shi wrote:

> centos , kernel(2.6.32)  
> 2015/11/28 14:41:11 [error] 12981#0: \*798323 recv() failed (104: Connection  
> reset by peer) while reading response header from upstream, client: xx.xx.xx.xx,  
> server: xx.xx.xx, request: “GET /ben2.php HTTP/1.1”, upstream:  
> “fastcgi://127.0.0.1:9000”, host: “xx.xx.xx”
> 
> 2015/11/28 14:41:08 [error] 12981#0: \*798215 connect() failed (110: Connection  
> timed out) while connecting to upstream, client: xx.xx.xx.xx, server: xx.xx.xx,  
> request: “GET /ben2.php HTTP/1.1”, upstream: “fastcgi://127.0.0.1:9000”, host:  
> “xx.xx.xx”
> 
> I’ve tried “request\_terminate\_timeout, fastcgi\_connect\_timeout,  
> fastcgi\_read/write\_timeout”, but no help.
> 
> What can I do next step ?

The “connection reset by peer” means that the connection was  
terminated by your backend, not by nginx. There isn’t much you  
can do on nginx side. Consider checking php-fpm logs instead, may  
be you are hitting some limit like execution time limit or  
something.

The “connection timed out” means that nginx wasn’t able to connect  
to the backend in time, fastcgi\_connection\_timeout is something  
you can tune - though the default is 60s, and it should be big  
enough for normal use. Again, consider looking into your backend  
to find out why connection takes so long - likely it’s overloaded  
and can’t process connection requests in time.

–  
Maxim D.

> **[nginx](http://nginx.org/)**
