公家網(wǎng)站模板百度代運營
文章目錄
- 問題描述
- 問題排查
- 問題解決
問題描述
服務(wù)器環(huán)境:
- php:8.4
- MySQL:8.0
- Nginx:1.26.2
在訪問站點時,一直報502,而兩天前還能正常訪問。
問題排查
導(dǎo)致502的問題很多,比如站點訪問量太大,站點受到了攻擊等,但是我看了后臺,重啟了Nginx,也沒解決?,F(xiàn)在遇到問題,首選就用AI
來診斷。
我先復(fù)制了網(wǎng)站的錯誤日志:
2025/03/07 13:16:26 [crit] 795740#0: *2451 connect() to unix:/tmp/php-cgi-84.sock failed (2: No such file or directory) while connecting to upstream, client: 66.249.66.21, server: www.imqd.cn, request: "GET /robots.txt HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi-84.sock:", host: "www.imqd.cn"
2025/03/07 13:16:26 [crit] 795740#0: *2450 connect() to unix:/tmp/php-cgi-84.sock failed (2: No such file or directory) while connecting to upstream, client: 66.249.66.1, server: www.imqd.cn, request: "GET /tag/es6 HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi-84.sock:", host: "www.imqd.cn"
丟給ChatGPT
,然后它回復(fù)的解決方案有點多,我用了下面這一條:
# 將該指令復(fù)制,并在站點目錄下執(zhí)行命令行
systemctl list-units --type=service | grep php
輸出:
php-fpm-74.service loaded active running LSB: starts php-fpm
● php-fpm-84.service loaded failed failed LSB: starts php-fpm
錯誤如上:
表示我的環(huán)境中安裝了2個php版本,其中Nginx 試圖使用 PHP 8.4 (php-fpm-84
),但它 無法啟動,所以 502 Bad Gateway。
問題解決
這個我之前是用PHP8.4
來運行WordPress
站點的,現(xiàn)在它的服務(wù)遇到了問題,導(dǎo)致502問題。
所以很簡單的解決方式就是將WordPress的PHP版本切換為7.4即可。
但是為什么會導(dǎo)致8.4
用不了呢?wp
運行在PHP8
中更安全。
查看PHP
的日志:
[14-Feb-2025 04:04:02] NOTICE: child 322153 stopped for tracing
[14-Feb-2025 04:04:02] NOTICE: about to trace 322153
[14-Feb-2025 04:04:02] NOTICE: finished trace of 322153
[15-Feb-2025 17:18:04] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 1 idle, and 22 total children
[15-Feb-2025 17:18:05] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 3 idle, and 26 total children
[16-Feb-2025 17:52:51] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 2 idle, and 27 total children
[16-Feb-2025 17:52:52] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 3 idle, and 30 total children
[16-Feb-2025 17:52:53] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 2 idle, and 32 total children
[17-Feb-2025 04:01:49] WARNING: [pool www] child 1221397, script '/www/wwwroot/www.cn/wp-admin/admin-ajax.php' (request: "GET /wp-admin/admin-ajax.php?action=wordfence_doScan&isFork=0&scanMode=standard&cronKey=c1d5082357026a61a2ce6e9feff7f549&signature=31aa3d000f5f2053ad504322212ad58a52a5a0e3032b25317bbdc7ef656b0606") executing too slow (34.708130 sec), logging
[17-Feb-2025 04:01:49] NOTICE: child 1221397 stopped for tracing
[17-Feb-2025 04:01:49] NOTICE: about to trace 1221397
[17-Feb-2025 04:01:49] NOTICE: finished trace of 1221397
[17-Feb-2025 10:57:21] NOTICE: Terminating ...
[17-Feb-2025 10:57:21] NOTICE: exiting, bye-bye!
發(fā)現(xiàn)了2個問題:
PHP-FPM 進程池(pool www)資源不足,服務(wù)器負載過高
- 日志多次提示 seems busy,說明 PHP 進程太少,導(dǎo)致請求等待時間變長。
- 你可能需要 增加 PHP-FPM 的進程數(shù)(
pm.start_servers
、pm.min/max_spare_servers
)。
某些 PHP 腳本執(zhí)行太慢,導(dǎo)致超時
- 日志中顯示 admin-ajax.php 執(zhí)行時間過長(34.7 秒),可能是 WordPress 插件(如 Wordfence)在運行掃描任務(wù),影響了服務(wù)器性能。
所以歸根結(jié)底還是服務(wù)器配置不夠,并且因為我開啟了Wordfence
插件掃描導(dǎo)致的原因。
如果你在開發(fā)WordPress時遇到了問題,可以在下方與我聯(lián)系,作為你的WordPress顧問。