Received an alert email today prompting the website 502 Bad Gateway,

Source: Internet
Author: User
Tags php open file website server

Received an alert email today prompting the website 502 Bad Gateway,

You cannot open the Web site URL after entering it:

Log on to the server to see Nginx process OK:

To view the FASTCGI process has stopped running:

Problems found after the search is what the cause of the problem, the first fastcgi process started after the site can access the reasons for fine.

View PHP log tail–n 1000/usr/local/php/logs/php-fpm.log

"Linux commune http://www.linuxidc.com"

Find the alarm point in the log information, where the highlight is the problem, the system maximum number of files is 1024, and the current number of open files is 1024, view php-fpm.conf:

<value name= "Rlimit_files" >65535</value>

So is the system file opening number becomes the bottleneck, causes the PHP open file number to reach the system default maximum value and stops the process.

Then increase the number of system files.

#ulimit –HSN 65535

#echo ' ULIMIT–HSN 65535 ' &gt;&gt;/etc/profile

#echo ' ULIMIT–HSN 65535 ' &gt;&gt;/etc/rc.local

# vim/etc/security/limits.conf

* Soft Nofile 65535
* Hard Nofile 65535

For servers that can reboot the system, it is best to reboot so that the changed parameters take effect globally.

A script that monitors PHP and is able to restart automatically:

#cat/usr/local/bin/fastcgi_monitor.sh

#!/bin/sh
#xxx监控
#!/bin/bash
State= ' Curl--head http://www.linuxidc.net | awk ' Nr==1 ' | awk ' {print $} '
If ["$STATE"-eq "502"]; Then
/etc/init.d/fastcgi restart

echo "FastCGI restarted" | Mutt-s "x.x.x.x website server fastcgi restarted" [email protected]
elif ["$STATE"-ne "502"] && ["$STATE"-ne "200"]; Then
/etc/init.d/nginx restart
/etc/init.d/fastcgi restart

echo "fastcgi and Nginx restarted" | Mutt-s "x.x.x.x website server fastcgi and Nginx restarted" [email protected]

Fi

*/10 * * * * sh/usr/local/bin/fastcgi_monitor.sh &gt;/tmp/fastcgi_monitor.log 2&gt;&1 &

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.