共计 2446 个字符,预计需要花费 7 分钟才能阅读完成。
大家好,我是阿蒲,之前有一篇是關於說明520錯誤的,這次我們來深度解析5xx之狀態碼
介紹5xx狀態碼
500系列的錯誤通常都是伺服器端所引起的
1. 500 Internal Server Error
伺服器遇到未預期的錯誤,無法完成請求。
例如:wp出現資料庫連結失敗、Flarum出現資料庫連結失敗、配置文件
解決
如果是資料庫的話請先檢查您的帳號密碼是否輸入正確
2. 501 Not Implemented
HTTP 501 狀態碼表示「伺服器不支持請求所需要的功能」。簡單說,就是客戶端發送了一個伺服器無法識別或無法處理的請求方法(HTTP Method)或功能,伺服器告訴你「這項功能我沒實作,無法執行」。
備註:這不常見
3. 502 Bad Gateway
這個依據我的經驗通常是這樣的:
- CC 攻擊是 L7(應用層)攻擊,會造成伺服器不斷產生 PHP 請求,最後讓 PHP-FPM 死掉、連接不上。
在log檔會出現
connect() to unix:/run/php/php8.2-fpm.sock failed (111: Connection refused)
2. 是你伺服器還沒安裝php並且也conf配置裡面已經有PHP配置了
例如:你在conf配置文件鍵入以下文字
location ~ \.php$ { include fastcgi_params; fastcgi_pass unix:/run/php/php8.2-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;}
然後你在error.log會看到
connect() to unix:/run/php/php8.2-fpm.sock failed (2: No such file or directory) while connecting to upstream
3. PHP權限錯誤
你在PHP www.conf中,若是非nginx用戶(ex. nginx www-data等),也會出現
user = nobody
group = nobody
或者
#user = nobody
#group = nobody
在error.log中會出現
connect() to unix:/run/php/php8.2-fpm.sock failed (13: Permission denied) while connecting to upstream
4. 反向代理配置文件
5. 關閉PHP
如果輸入systemctl stop php-fpm
時會出現

在nginx error.log出現
connect() to unix:/run/php/php8.3-fpm.sock failed (2: No such file or directory)
備註:這個502非常常見,且cf有緩存
4. 503 Service Unavailable
伺服器過載或停機維護。通常需要檢查伺服器負載狀況或維護排程。
1. 手動配置
在網站配置文件時插入
return 503
2. 權限錯誤(特定)
如果你有安裝HttpGuard的話,如果是權限非
root@acrobatic-leader:/etc/nginx/HttpGuard# ls -l
total 440
drwxrwx--- 2 nginx nginx 249856 May 21 19:41 captcha
-rw-rw---- 1 nginx nginx 7221 May 31 11:41 config.lua
-rw-rw---- 1 nginx nginx 31340 Jun 20 2017 guard.lua
drwxrwx--- 2 nginx nginx 51 May 14 07:22 html
-rw-rw---- 1 nginx nginx 5794 Jun 20 2017 init.lua
drwxrwx--- 2 nginx nginx 162 May 31 07:10 logs
-rw-rw---- 1 nginx nginx 100 Jun 20 2017 README.md
-rw-rw---- 1 nginx nginx 2692 Jun 20 2017 runtime.lua
drwxrwx--- 2 nginx nginx 95 May 14 07:22 url-protect
就會爆503
備註:此報錯極為罕見
5. 521 Web Server Is Down
意思:Cloudflare 無法與你的伺服器建立連線(TCP 層失敗)
✅ 常見原因:
- 伺服器上的 Web 服務(如 Nginx、Apache)根本沒啟動
- 伺服器防火牆封鎖了 Cloudflare 的 IP
- Nginx 配置錯誤或主機拒絕連線(listen 配錯、錯綁回環)
6. 522 Connection Timed Out
當你遇到 522 錯誤時,這代表「連線超時」。這裡是最常見的三個原因:
1️⃣ Cloudflare 的 IP 被防火牆阻擋
伺服器端防火牆(如 iptables、firewalld)誤把 Cloudflare 的回源 IP 當成攻擊流量封鎖,導致 Cloudflare 無法與你的伺服器正常通訊。
✅ 解法:將 Cloudflare IP 加入白名單。
2️⃣ 伺服器未開放 80/443 端口
Cloudflare 回源時使用 HTTP(80)或 HTTPS(443)連線,如果你的伺服器沒開這些端口,或防火牆擋了這些連線,就會導致超時。
✅ 解法:確認伺服器上防火牆未封鎖 80/443。
3️⃣ 伺服器忙不過來或崩潰
有時候是伺服器自身 CPU 爆滿或記憶體被吃光,導致 PHP-FPM 無法即時回應,甚至被 OOM Killer
(系統保護機制)強制殺掉。這種情況請求就會一直卡住,最終回傳 504或有些是502。
✅ 解法:
- 檢查
top
/htop
查看 CPU、RAM 使用狀況 - 檢查
/var/log/php*/error.log
是否有崩潰記錄 - 看看 PHP-FPM 是否還在運作
7. 525 SSL Handshake Failed
代表:Cloudflare 嘗試與你的伺服器建立 HTTPS 連線,但握手失敗
✅ 常見原因:
- 伺服器上 SSL 憑證配置錯誤
- Nginx 沒有 listen
443 ssl
或憑證格式錯誤 - 憑證已過期
- Cloudflare 設為「完全加密(Full)」但伺服器只支援 HTTP