Welcome! Log In Create A New Profile

Advanced

Upstream keepalive and fastcgi_next_upstream

August 30, 2016 06:57AM
Hello I notice strange behavior with keepalive and upstream module.

I've backend PHP-FPM with setting configuration

request_terminate_timeout = 5s

And nginx config:

upstream phpfpm {
server unix:/tmp/php-fpm-7.sock max_fails=0 fail_timeout=1s;
keepalive 8;
}

location ^\*.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_connect_timeout 1;
fastcgi_next_upstream error timeout http_503;
fastcgi_keep_conn on;
fastcgi_intercept_errors on;
fastcgi_pass phpfpm;
}

Then I write simple PHP script which generate 10sec timeout.
So phpfpm get error when "request_terminate_timeout" exceeded, and I'm expecting that Nginx also get error 502
but it try send request to upstream again and again.
I have such errors in my error log:

2016/08/30 10:22:34 [error] 92078#0: *558411 upstream prematurely closed connection while reading response header from upstream, client: 1.2.3.4, server: my.com, request: "GET /?time_out=10 HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fpm-7.sock:", host: "
my.com"
2016/08/30 10:22:39 [error] 92078#0: *558411 upstream prematurely closed connection while reading response header from upstream, client: 1.2.3.4, server: my.com, request: "GET /?time_out=10 HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fpm-7.sock:", host: "
my.com"
2016/08/30 10:22:40 [error] 92078#0: *558411 upstream prematurely closed connection while reading response header from upstream, client: 1.2.3.4, server: my.com, request: "GET /?time_out=10 HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fpm-7.sock:", host: "
my.com"
2016/08/30 10:22:42 [error] 92078#0: *558411 upstream prematurely closed connection while reading response header from upstream, client: 1.2.3.4, server: my.com, request: "GET /?time_out=10 HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-fpm-7.sock:", host: "
my.com"


When I disable keepalive directive in upstream determination section

upstream phpfpm {
server unix:/tmp/php-fpm-7.sock max_fails=0 fail_timeout=1s;
}

- I get 502 ~6 sec. It's corresponding my request_terminate_timeout

My version - nginx/1.8.0
Subject Author Posted

Upstream keepalive and fastcgi_next_upstream

vizl August 30, 2016 06:57AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 140
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready