nginx下php頻繁卡死502

2022-07-01 20:18:14 字數 2152 閱讀 4887

試用nginx + php fastcgi 做web伺服器,執行了幾個月的時間,煩惱的是經常碰到nginx 502 bad gateway 這個問題。

參考了很多修改辦法,這個502的問題一直存在,今天打算重灌php fastcgi到php的安裝目錄裡一看,發現php的日誌檔案已經有幾十m的大小,開啟一看,結果基本全部都是一下的錯誤:

jan 11 08:54:01.164292 [notice] fpm_children_make(), line 352: child 10088 (pool default) started

jan 11 08:54:01.164325 [warning] fpm_children_bury(), line 215: child 7985 (pool default) exited on signal 15 sigterm after 63.778601 seconds from start

jan 11 08:54:01.165485 [notice] fpm_children_make(), line 352: child 10089 (pool default) started

jan 11 08:54:01.165514 [warning] fpm_children_bury(), line 215: child 7999 (pool default) exited on signal 15 sigterm after 60.297326 seconds from start

jan 11 08:54:01.166696 [notice] fpm_children_make(), line 352: child 10090 (pool default) started

jan 11 08:54:01.166727 [warning] fpm_children_bury(), line 215: child 8000 (pool default) exited on signal 15 sigterm after 60.296946 seconds from start

jan 11 08:54:01.167855 [notice] fpm_children_make(), line 352: child 10091 (pool default) started

jan 12 04:00:50.443884 [notice] fpm_children_make(), line 352: child 10127 (pool default) started

jan 12 04:00:50.443917 [notice] fpm_event_loop(), line 107: libevent: entering main loop

jan 12 12:05:08.425141 [warning] fpm_request_check_timed_out(), line 158: child 10120, script '/home/htdocs/www/index.php' (pool default) execution timed out (30.051306 sec), terminating

查過網上的資源,基本都是認為是php執行緒開啟檔案控制代碼受限導致的錯誤。具體的解決的辦法如下:

1、提公升伺服器的檔案控制代碼開啟開啟

/etc/security/limits.conf : (增加)

*    soft    nofile    51200

*    hard    nofile    51200

# vi /etc/security/limits.conf 加上

* soft nofile 51200

* hard nofile 51200

2、提公升nginx的程序檔案開啟數

nginx.conf : worker_rlimit_nofile 51200;

3、修改php-fpm.conf檔案,主要需要修改2處

命令 ulimit -n 檢視限制的開啟檔案數,php-fpm.conf 中的選項rlimit_files 確保和此數值一致。

10240

51200

4、# vi /etc/sysctl.conf 

底部新增

fs.file-max=51200

完成以上修改,重啟php,警告資訊再也沒了。

世界從此安寧,502 bad gateway 沒有了。

Nginx環境下Php安裝

其實很簡單的事,我每次安裝貌似都會走彎路,所以還是記下來吧 centos 5.5 nginx 1.0.5 php 5.5.81.先安裝nginx tar zxvf nginx 1.0.5.tar.gz cd nginx 1.0.5 configure make make install2.安裝php...

docker下安裝nginx和php

我使用的是centos7.0系統,具體安裝要求,大家可以去官網上查詢 sudo yum config manager add repo 新增源資訊 sudo yum makecache fast 更新yum快取 sudo yum y install docker ce 安裝ce版本 sudo sys...

linux下nginx多版本php共存

lnmp的環境,當前php版本5.3.8,遇到乙個應用需求只支援php 5.2.x,又希望保持現有應用還是用php 5.3.8。也就是說需要兩個版本的php同時存在,供nginx根據需要呼叫不同版本。nginx是通過php fastcgi與php互動的。而php fastcgi執行後會通過檔案 或本...