nginx跑php-cgi会碰到502 Bad Gateway

nginx跑php-cgi会碰到502 Bad Gateway

http://bbs2.chinaunix.net/thread-1187040-1-1.html


用apache ab 在512M内存的as4机上测试
worker_processes 4;
<value name="max_children">20</value>

     fastcgi_connect_timeout 60;
     fastcgi_send_timeout 180;
     fastcgi_read_timeout 180;
     fastcgi_buffer_size 128k;
     fastcgi_buffers 4 128k;
     fastcgi_busy_buffers_size 128k;
     fastcgi_temp_file_write_size 128k;
     fastcgi_temp_path /dev/shm;


ab -n5000 -c1000 http://devwebapp.xxx.com/insert.php


Server Software:        nginx/0.6.32
Server Hostname:        devwebapp.xxx.com
Server Port:            80

Document Path:          /insert.php
Document Length:        3437 bytes

Concurrency Level:      1000
Time taken for tests:   77.981352 seconds
Complete requests:      5000
Failed requests:        663  
(Connect: 0, Length: 663, Exceptions: 0)
Write errors:           0
Non-2xx responses:      663
Total transferred:      16065252 bytes
HTML transferred:       14983962 bytes
Requests per second:    64.12 [#/sec] (mean)
Time per request:       15596.271 [ms] (mean)
Time per request:       15.596 [ms] (mean, across all concurrent requests)
Transfer rate:          201.18 [Kbytes/sec] received


     fastcgi_connect_timeout 30;


Server Software:        nginx/0.6.32
Server Hostname:        devwebapp.xxx.com
Server Port:            80

Document Path:          /insert.php
Document Length:        3437 bytes

Concurrency Level:      1000
Time taken for tests:   69.152495 seconds
Complete requests:      5000
Failed requests:        1281
   (Connect: 0, Length: 1281, Exceptions: 0)
Write errors:           0
Non-2xx responses:      1281
Total transferred:      14065785 bytes
HTML transferred:       13016286 bytes
Requests per second:    72.30 [#/sec] (mean)
Time per request:       13830.499 [ms] (mean)
Time per request:       13.830 [ms] (mean, across all concurrent requests)
Transfer rate:          198.63 [Kbytes/sec] received

我减少-c 到500和200 也会出现502,只是数量等比缩小了。
是fastcgi_connect_timeout 的问题?为什么会这样呢?除了增加超时时间外还有什么办法?
我的设置是这样的
    fastcgi_connect_timeout 500;
      fastcgi_send_timeout 500;
      fastcgi_read_timeout 500;

如果请求量很小的情况是否有好转?
还有,你可以适当增加php-cgi的进程数量,我不知道你是怎么启动php-cgi的,我是用lighttd的那个东东启动的。我启动了32个。你试试看?
我也遇到过,后来不用这个了,你看看日志呢
fastcgi,只要内存允许,进程数量尽量多就可以了
502 bad gateway

1.我以前使用zeus web server也遇到过此类问题.问题当时是出现php本身安装上或是PHP版本有问题,具体看一下错误信息.建议重新安装php或是注意php关于fast-cgi补丁等.

2.如果实在不行.就是chinaittab.找一个安装教程.使用新版本的nginx0.7.19+php-5.2+mysql-5.1,重新布置一下自己的环境.