Web 服務故障排除指南
ServBay 支持使用 Caddy、NGINX、Apache 作為預設的 Web 伺服器,在日常使用中,使用者可能會碰到網站無法打開等一些問題,下面是一些常見問題的解決方法。
使用 ServBay 自帶工具排障
ServBay 自帶了功能非常強大的故障診斷工具,我們建議使用 ServBay 自帶的故障排除工具來自助診斷和解決問題。
打開 ServBay 應用,在左側導航中找到故障診斷
,即可進入 ServBay 自帶的故障診斷工具。
檢查配置文件
Caddyfile 檢查
使用 Caddy 內建的驗證功能來驗證 Caddyfile 是否正確。請執行下面的命令。
$ /Applications/ServBay/bin/caddy validate -c /Applications/ServBay/etc/caddy/Caddyfile
如果返回Valid configuration
,那就表示一切正常。如果返回其他錯誤代碼,請根據錯誤代碼的提示進行下一步的操作。(注意:上面的命令會有大量的 INFO 和 WARN 輸出,這是正常情況,不會影響服務的正常運行)
證書錯誤
如果出現類似下面的錯誤loading certificates: open xxxxx: no such file or directory
,那就意味著證書文件不存在。請檢查證書文件的地址是否正確。
2024/12/09 17:24:16.970 INFO using config from file {"file": "/Applications/ServBay/etc/caddy/Caddyfile"}
2024/12/09 17:24:16.991 INFO adapted config to JSON {"adapter": "caddyfile"}
2024/12/09 17:24:16.991 WARN Caddyfile input is not formatted; run 'caddy fmt --overwrite' to fix inconsistencies {"adapter": "caddyfile", "file": "/Applications/ServBay/etc/caddy/Caddyfile", "line": 8}
2024/12/09 17:24:16.999 INFO tls.cache.maintenance started background certificate maintenance {"cache": "0x1400121f300"}
2024/12/09 17:24:17.006 INFO tls.cache.maintenance stopped background certificate maintenance {"cache": "0x1400121f300"}
Error: loading http app module: provision http: getting tls app: loading tls app module: provision tls: loading certificates: open /Applications/ServBay/ssl/private/tls-certs/mail.servbay.host/mail.servbay.host.1crt: no such file or directory
2
3
4
5
6
7
網站目錄錯誤
如果出現下面的錯誤parsing caddyfile tokens for 'root': too many arguments
,請檢查網站目錄的路徑中是否存在空格。這是一個非常常見的錯誤。
例如root * /Applications/ServBay/www/public web
,在 public
和 web
之間有一個空格,這樣會被當做兩個參數,導致錯誤。正確的設置方法是使用雙引號(")將路徑包裹起來。比如root * "/Applications/ServBay/www/public web"
。
我們強烈建議不要在任何檔名、路徑中包含空格和特殊符號。對於單詞的分隔,可以使用-
或者_
符號,比如:public-folder
、public_dir
。
2024/12/09 17:26:37.371 INFO using config from file {"file": "/Applications/ServBay/etc/caddy/Caddyfile"}
Error: adapting config using caddyfile: parsing caddyfile tokens for 'root': too many arguments; should only be a matcher and a path, at /Applications/ServBay/etc/caddy/Caddyfile:1388
2
3
Rewrite 規則錯誤
在 Caddy 中使用了不正確的 Rewrite 規則,例如直接使用 NGINX 的規則,也會導致錯誤。
NGINX 配置檢查
使用以下命令檢查 NGINX 配置是否正確:
$ /Applications/ServBay/bin/nginx -t
如果配置正確,會顯示:
nginx: the configuration file /Applications/ServBay/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /Applications/ServBay/etc/nginx/nginx.conf test is successful
2
常見錯誤包括:
- 語法錯誤(如缺少分號)
- 檔案路徑錯誤
- 埠衝突
Apache 配置檢查
使用以下命令檢查 Apache 配置:
$ /Applications/ServBay/bin/apachectl configtest
常見錯誤包括:
- 模組加載失敗
- .htaccess 檔案語法錯誤
- 目錄權限設置不當
500 錯誤處理
500 內部伺服器錯誤是常見的 Web 伺服器錯誤,可能由多種原因引起:
通用排查步驟
檢查伺服器錯誤日誌:
- Caddy:
/Applications/ServBay/var/logs/caddy/error.log
- NGINX:
/Applications/ServBay/var/logs/nginx/error.log
- Apache:
/Applications/ServBay/var/logs/apache/error.log
- Caddy:
檢查 PHP 服務是否啟動
bashps aux | grep php-fpm
1檢查 PHP 錯誤(如果使用 PHP):
/Applications/ServBay/var/logs/php/php_error.log
檢查檔案權限:
bash$ ls -la /Applications/ServBay/www/your-site
1確保 Web 伺服器用戶有讀取權限
Caddy 特有 500 錯誤
- 檢查 FastCGI 配置是否正確
- 確保 PHP-FPM 服務正在運行
- 驗證反向代理設置
NGINX 特有 500 錯誤
- 檢查
fastcgi_pass
設置是否正確 - 驗證
client_max_body_size
是否足夠大 - 檢查
try_files
指令配置
Apache 特有 500 錯誤
- 檢查
mod_rewrite
是否啟用 - 驗證
.htaccess
檔案內容 - 檢查
AllowOverride
設置
服務管理
重啟服務
如果修改了配置,需要重啟相應服務:
# Caddy
$ servbayctl restart caddy -all
# NGINX
$ servbayctl restart nginx -all
# Apache
$ servbayctl restart apache -all
2
3
4
5
6
7
8
查看服務狀態
# Caddy
$ servbayctl status caddy -all
# NGINX
$ servbayctl status nginx -all
# Apache
$ servbayctl status apache -all
2
3
4
5
6
7
8
高級排障
如果以上方法無法解決問題,可以嘗試:
- 臨時關閉防火牆測試
- 使用
curl -v
查看詳細請求信息 - 在不同瀏覽器/設備上測試
- 檢查 DNS 解析是否正確
如需進一步幫助,請聯繫 ServBay 技術支持團隊。