我在配置 httpd 以接受大型 SPNEGO 身份驗證標頭時遇到問題。該請求在授權標頭行至少為 5674 位元組時運作正常,但在授權標頭行超過 6178 位元組時中斷,答案如下:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
Size of a request header field exceeds server limit.</p>
</body></html>
伺服器日誌中出現以下錯誤(調試等級)
[Thu Aug 23 07:26:31 2018] [error] [client x.x.x.x] request failed: error reading the headers
這是我們啟動的伺服器資訊頁面的摘錄,以確保 LimitRequestFieldSize 足夠高
129: LimitRequestBody 52428800
130: LimitRequestFields 50
131: LimitRequestFieldsize 40960
132: LimitRequestLine 40960
伺服器正在運行 RHEL 6.7 和 Stock httpd 伺服器
$ httpd -V
Server version: Apache/2.2.15 (Unix)
Server built: Mar 3 2015 12:06:14
Server's Module Magic Number: 20051115:25
Server loaded: APR 1.3.9, APR-Util 1.3.9
Compiled using: APR 1.3.9, APR-Util 1.3.9
Architecture: 64-bit
Server MPM: Prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APACHE_MPM_DIR="server/mpm/prefork"
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=128
-D HTTPD_ROOT="/etc/httpd"
-D SUEXEC_BIN="/usr/sbin/suexec"
-D DEFAULT_PIDLOG="run/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_LOCKFILE="logs/accept.lock"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"
答案1
在我的帶有 Apache 2.4 的 Ubuntu 18.04 LTS 機器上,我修改了該檔案:
/etc/apache2/conf-available/httpd.conf
根據文件https://httpd.apache.org/docs/2.4/mod/core.html
# https://askubuntu.com/questions/340792/size-of-a-request-header-field-exceeds-server-limit-due-to-many-if-none-match-va
# default is 8k see https://httpd.apache.org/docs/2.4/mod/core.html
LimitRequestFieldSize 32768
# default is 100
LimitRequestFields 200
並重新啟動伺服器。您可能想要修改設定
答案2
編輯您的虛擬主機並查看有關請求大小的限制。
您可以檢查 httpd.h 中的預設值(例如 DEFAULT_LIMIT_REQUEST_FIELDSIZE)
例 :
<VirtualHost ...>
ServerName www.mysite.com
...
#HTTP Request
LimitRequestFieldSize 32768
LimitRequestFields 200
LimitXMLRequestBody 0
...
</VirtualHost>
答案3
如果您將 LimitRequest 指令放入伺服器設定中,則必須在 VirtualHost 設定之前插入這些指令。