Chinaunix首页 | 论坛 | 博客
  • 博客访问: 40891
  • 博文数量: 20
  • 博客积分: 768
  • 博客等级: 军士长
  • 技术积分: 395
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-18 15:03
文章分类

全部博文(20)

文章存档

2012年(20)

我的朋友

分类: 系统运维

2012-05-09 11:48:50

导致nginx 502 bad gateway的PHP-CGI(FASTCGI)

NGINX频爆502 BAD GATEWAY的错误,看了网上的教程,仍没有彻底解决。

目前我总结的解决502 BAD GATEWAY的方式有:

1.视性能,在php-fmp.conf里增加max_children的值,我目前用的15.

2.用reload参数定时重载php-fpm。这个主要原因是php脚本执行时间过长造成的,重载php-fpm能杜绝这个问题。如何彻底解决php-cgi脚本占用大量内存从而导致502错误的产生还值得进一步探讨,目前该做法不失为一种好办法。

具体的做法是,用crontab让php-fpm平滑重启,从而不影响PHP脚本的运行。

*/10 * * * * /usr/local/php/sbin/php-fpm reload

When you running a highload website with PHP-FPM via FastCGI, the following tips may be useful to you : )

如果您高负载网站使用PHP-FPM管理FastCGI,这些技巧也许对您有用:)

1. Compile PHP’s modules as less as possible, the simple the best (fast);

1.尽量少安装PHP模块,最简单是最好(快)的

2. Increas PHP FastCGI child number to 100 and even more. Sometime, 200 is OK! ( On 4GB memory server);

2.把您的PHP FastCGI子进程数调到100或以上,在4G内存的服务器上200就可以

注:我的1g测试机,开64个是最好的,建议使用压力测试获取最佳值

3. Using SOCKET PHP FastCGI, and put into /dev/shm on Linux;

3.使用socket连接FastCGI,linux操作系统可以放在 /dev/shm中

注:在php-fpm.cnf里设置/tmp/nginx.socket就可以通过socket连接FastCGI了,/dev/shm是内存文件系统,放在内存中肯定会快了

4. Increase Linux “max open files”, using the following command (must be root):

# echo ‘ulimit -HSn 65536′ >> /etc/profile

# echo ‘ulimit -HSn 65536 >> /etc/rc.local

# source /etc/profile

4.调高linux内核打开文件数量,可以使用这些命令(必须是root帐号)

echo ‘ulimit -HSn 65536′ >> /etc/profile

echo ‘ulimit -HSn 65536′ >> /etc/rc.local

source /etc/profile

注:我是修改/etc/rc.local,加入ulimit -SHn 51200的

5. Increase PHP-FPM open file description rlimit:

# vi /path/to/php-fpm.conf

Find “1024

Change 1024 to 4096 or higher number.

Restart PHP-FPM.

5. 增加 PHP-FPM 打开文件描述符的限制:

# vi /path/to/php-fpm.conf

找到“1024

把1024 更改为 4096
阅读(1297) | 评论(2) | 转发(1) |
给主人留下些什么吧!~~

十七岁的回忆2012-05-09 22:22:07

恩,比较实用的办法

☆彼岸★花开2012-05-09 22:18:51

不错,很有用的说~~博主辛苦啦~