是否有一个可接受的HTTP头的最大允许大小?如果有,是什么?如果不是,这是特定于服务器的东西,还是允许任何大小的头的公认标准?


当前回答

这是最流行的网络服务器的限制

Apache - 8K Nginx - 4K-8K Iis - 8k-16k 雄猫- 8K - 48K 节点(<13)- 8K;(>13) - 16k

其他回答

不,HTTP没有定义任何限制。然而,大多数web服务器确实限制了它们接受的头文件的大小。例如,在Apache的默认限制是8KB,在IIS是16K。如果报头大小超过限制,服务器将返回413实体过大错误。

相关问题:用户代理字符串可以有多大?

正如vartec上面所说,HTTP规范没有定义限制,但是许多服务器默认情况下是这样做的。这意味着,实际上,下限是8K。对于大多数服务器,这个限制适用于请求行和ALL报头字段的总和(所以保持您的cookie简短)。

Apache 2.0, 2.2: 8K nginx: 4K - 8K IIS:不同版本不同,8K - 16K Tomcat:根据版本不同,8K - 48K (?!)

值得注意的是,nginx默认使用系统页面大小,在大多数系统上是4K。你可以用这个小程序来检查:

pagesize.c:

#include <unistd.h>
#include <stdio.h>

int main() {
    int pageSize = getpagesize();
    printf("Page size on your system = %i bytes\n", pageSize);
    return 0;
}

使用gcc -o pagesize pagesize.c编译,然后运行。/pagesize。我在Linode的ubuntu服务器尽职尽责地告诉我答案是4k。

这是最流行的网络服务器的限制

Apache - 8K Nginx - 4K-8K Iis - 8k-16k 雄猫- 8K - 48K 节点(<13)- 8K;(>13) - 16k

我还发现在某些情况下,在许多头文件的情况下出现502/400的原因可能是因为有大量的头文件而不考虑大小。 来自文档

tune.http.maxhdr Sets the maximum number of headers in a request. When a request comes with a number of headers greater than this value (including the first line), it is rejected with a "400 Bad Request" status code. Similarly, too large responses are blocked with "502 Bad Gateway". The default value is 101, which is enough for all usages, considering that the widely deployed Apache server uses the same limit. It can be useful to push this limit further to temporarily allow a buggy application to work by the time it gets fixed. Keep in mind that each new header consumes 32bits of memory for each session, so don't push this limit too high.

https://cbonte.github.io/haproxy-dconv/configuration-1.5.html#3.2-tune.http.maxhdr

如果您打算使用任何像Akamai这样的DDOS提供商,他们的响应头大小最大限制为8k。所以尽量将响应头大小限制在8k以下。