Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

網站 501 Method Not Implemented 錯誤:mod_security 衝突解決

編輯:關於伺服器

錯誤現象

501 Method Not Implemented
The requested method is not implemented by this server.

根因:mod_security 封鎖非標準 HTTP 方法

OPTIONS、TRACE、CONNECT、PATCH 等方法被 mod_security 規則攔截。

解決方案一:停用 mod_security (快速止血)

方法 A:註釋模組載入

# /etc/httpd/conf.d/mod_security.conf
# LoadFile /usr/lib/libxml2.so.2
# LoadModule security_module modules/mod_security2.so
# LoadModule unique_id_module modules/mod_unique_id.so

方法 B:.htaccess 關閉引擎 (無需重啟)

<IfModule mod_security.c>
    SecFilterEngine Off
    SecFilterScanPOST Off
</IfModule>

解決方案二:精準放行 (推薦生產環境)

# mod_security.conf 或 crs-setup.conf
# 允許 OPTIONS (CORS 預檢必需)
SecRule REQUEST_METHOD "^OPTIONS$" "id:10001,phase:1,pass,nolog,ctl:ruleEngine=Off"

# 允許 PATCH (RESTful API 常用)
SecRule REQUEST_METHOD "^PATCH$" "id:10002,phase:1,pass,nolog"

# 或調整 CRS 規則
SecAction "id:900130,phase:1,pass,nolog,setvar:tx.allowed_methods=GET HEAD POST OPTIONS PUT DELETE PATCH"

驗證 OPTIONS 方法支援

$ telnet www.example.com 80
Trying 192.0.32.10...
Connected to www.example.com.
Escape character is '^]'.
OPTIONS / HTTP/1.1
Host: www.example.com

HTTP/1.1 200 OK
Allow: GET, HEAD, POST, OPTIONS, TRACE
Content-Length: 0
Connection: close

避坑指南

  • 完全停用 mod_security 等於裸奔,**必須**在 WAF/雲防火牆層面補上防護
  • RESTful API 需支援 PUT/DELETE/PATCH,逐一放行而非全開
  • CORS 跨域請求**必須**支援 OPTIONS 預檢,否則前端調用失敗
  • TRACE 方法建議永久禁用 (XST 攻擊風險):TraceEnable Off

Nginx 同類問題 (參考)

# Nginx 預設支援常見方法,若需限制
location / {
    limit_except GET POST HEAD { deny all; }
    # 或自定義錯誤頁
    error_page 405 /405.html;
}
Copyright © Windows教程網 All Rights Reserved