linux nginx website access prompts 502 Bad Gateway

Published: 2013-12-06

Based on the log error analysis, this is caused by php threads being restricted in opening file handles. Solution:

1. Increase the server's file handle open limit
vi /etc/security/limits.conf, add at the bottom
* soft nofile 51200
* hard nofile 51200

vi /etc/sysctl.conf  add at the bottom
fs.file-max=51200

2. Increase the number of files nginx processes can open
vi /www/wdlinux/nginx/conf/nginx.conf
worker_rlimit_nofile 5120; change to worker_rlimit_nofile 51200;

3. Modify the php-fpm.conf file; mainly 2 places need to be modified.
vi /www/wdlinux/etc/php-fpm.conf
Change to the following values
<value name="max_requests">10240</value>
<value name="rlimit_files">51200</value>

4. Set php-fpm to start automatically
vi /etc/rc.local, add at the end
/etc/init.d/php-fpm start

After completion, reboot the server
Check with ulimit -n