We run the following stack on our web server Varnish + Nginx + FastCGI (php-fpm) on RHEL 6.6
Its a dynamic website with different result sets every time and has around 2 million URLs indexed by Google.
- Its launch on nginx / 1.5.12 and PHP 5.3.3 (will be updated to the latest nginx and PHP soon)
- Nginx connects to php-fpm running locally on the same server on port 9000
We periodically interrupt the 504 gateway timeout on some pages that we cannot resolve. The url that gives 504 works fine after some time. We learn about 504 from our magazines, and we were not able to reproduce this, because it randomly happens at any URL and works after some time.
I had some discussions with the developer, but according to him, the basic php script is unlikely to do something, and it should not last so long (120 seconds), but still it gives 504 Gateway timeouts.
It is necessary to establish exactly where the problem occurs:
- Is this a problem with nginx?
- Is this a problem with php-fpm?
- Is this a problem with basic php scripts?
- Is it possible that nginx cannot connect to php-fpm?
- Will it be allowed if we use a Unix socket instead of a TCP / IP connection?
URL expires in 120 seconds from 504
Below is the error: 2016/01/04 17:29:20 [error] 1070 # 0: * 196333149 upstream timed out (110: connection timeout) when connecting to the upstream, client: 66.249.74.95, server: xxxx, request : "GET / Some / url HTTP / 1.1", upstream: "fastcgi: //127.0.0.1: 9000", host: "example.com"
fastcgi_connect_timeout 150 - 502 63 net.ipv4.tcp_syn_retries = 5 RHEL 6.6; net.ipv4.tcp_syn_retries = 6, 502 127 .
fastcgi_connect_timeout = 120, 504. , fastcgi_connect_timeout .
, 504 ( , ). , .
, ?
-:
nginx.conf:
- keepalive_timeout 5;
- send_timeout 150;
vhost.conf:
- proxy_send_timeout 100
- proxy_read_timeout 100
- proxy_connect_timeout 100
- fastcgi_connect_timeout 120
- fastcgi_send_timeout 300
- fastcgi_read_timeout 300
-, , - .
sysctl.conf:
- net.ipv4.ip_local_port_range = 1024 65500
- net.ipv4.tcp_fin_timeout = 10
- net.ipv4.tcp_tw_reuse = 1
- net.ipv4.tcp_syn_retries = 6
- net.core.netdev_max_backlog = 8192
- net.ipv4.tcp_max_tw_buckets = 2000000
- net.core.somaxconn = 4096
- net.ipv4.tcp_no_metrics_save = 1
- vm.max_map_count = 256000
, , 504 - php-, - nginx php-fpm, Nginx Php-fpm, .
, Advance!
======
:
2 :
2016/01/05 03:50:54 [error] 1070 # 0: * 201650845 upstream timed out (110: ) , : 66.249.74.99, server: xxxx, request: GET/some/url HTTP/1.1 ", upstream: "fastcgi://127.0.0.1: 9000", host: "example.com"
- 504 @300 , :
2016/01/05 00:51:43 [error] 1067 # 0: * 200656359 upstream timed out (110: ) , : 115.112.161.9, : 192.168.12.101, : "GET/some/url HTTP/1.1", : "fastcgi://127.0.0.1: 9000", : "example.com"