apache 的最大 url 长度是多少?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1289585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 18:04:49  来源:igfitidea点击:

What is apache's maximum url length?

apachehttpurl

提问by Stef

What is the maximum length of a URL in apache? Where is it documented, and is it configurable?

apache中URL的最大长度是多少?它在哪里记录,是否可以配置?

I'm implementing an openid identity provider, and would like to know the limitations I'm up against. I know about the 2048 byte path limit on Internet Explorer. That can be handled specially using user agent detection. Other browsers have much higher URL limits.

我正在实施一个 openid 身份提供者,并想知道我遇到的限制。我知道 Internet Explorer 上的 2048 字节路径限制。这可以使用用户代理检测来专门处理。其他浏览器的 URL 限制要高得多。

So what I'm interested in is apache server limits when coding an application.

所以我感兴趣的是编写应用程序时 apache 服务器的限制。

回答by Gumbo

The default limit for the length of the request lineis 8190 bytes (see LimitRequestLinedirective). And if we subtract three bytes for the request method (i.e. GET), eight bytes for the version information (i.e. HTTP/1.0/HTTP/1.1) and two bytes for the separating space, we end up with 8177 bytes for the URI path plus query.

请求行长度的默认限制为8190 字节(请参阅LimitRequestLine指令)。如果我们减去请求方法(即GET)的三个字节,版本信息(即HTTP/1.0/ HTTP/1.1)的八个字节和分隔空间的两个字节,我们最终得到 8177 个字节的 URI 路径和查询。

回答by lo_fye

  • Internet Explorer: 2,083 characters, with no more than 2,048 characters in the path portion of the URL
  • Firefox: 65,536 characters show up, but longer URLs do still work even up past 100,000
  • Safari: > 80,000 characters
  • Opera: > 190,000 characters
  • IIS: 16,384 characters, but is configurable
  • Apache: 4,000 characters
  • Internet Explorer:2,083 个字符,URL 的路径部分不超过 2,048 个字符
  • Firefox:显示 65,536 个字符,但即使超过 100,000 个,更长的 URL 仍然有效
  • Safari:> 80,000 个字符
  • 歌剧:> 190,000 个字符
  • IIS:16,384 个字符,但可配置
  • Apache:4,000 个字符

From: http://www.danrigsby.com/blog/index.php/2008/06/17/rest-and-max-url-size/

来自:http: //www.danrigsby.com/blog/index.php/2008/06/17/rest-and-max-url-size/

回答by RightFullRudder

The official length according to the offical Apache docs is 8,192, but many folks have run into trouble at ~4,000.

根据官方 Apache 文档,官方长度为 8,192,但许多人在大约 4,000 时遇到了麻烦。

MS Internet Explorer is usually the limiting factor anyway, as it caps the maximum URL size at 2,048.

无论如何,MS Internet Explorer 通常是限制因素,因为它将最大 URL 大小限制为 2,048。

回答by Tom Lime

Allowed default size of URI is 8177 characters in GET request. Simple code in python for such testing.

GET 请求中允许的 URI 的默认大小为 8177 个字符。用于此类测试的 Python 中的简单代码。

#!/usr/bin/env python2

import sys
import socket

if __name__ == "__main__":
    string = sys.argv[1]
    buf_get = "x" * int(string)
    buf_size = 1024
    request = "HEAD %s HTTP/1.1\nHost:localhost\n\n" % buf_get
    print "===>", request

    sock_http = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock_http.connect(("localhost", 80))
    sock_http.send(request)
    while True:
       print "==>", sock_http.recv(buf_size)
       if not sock_http.recv(buf_size):
           break
    sock_http.close()

On 8178 characters you will get such message: HTTP/1.1 414 Request-URI Too Large

在 8178 个字符上,您将收到这样的消息:HTTP/1.1 414 Request-URI Too Large

回答by estani

Here's a bash script to check the maximum limit of a remote server (uses curl and perl).

这是一个 bash 脚本,用于检查远程服务器的最大限制(使用 curl 和 perl)。

You just need some kind of an url that can be extended with 'x' and always return 200 (or adapt it to your needs). At some point it will break and the script will display the max length.

您只需要某种可以用“x”扩展并始终返回 200(或根据您的需要进行调整)的网址。在某些时候它会中断,脚本将显示最大长度。

Here's the code:

这是代码:

url='http://someurl/someendpoint?var1=blah&token='
ok=0
times=1

while :; do
    length=$((times+${#url}))
    echo trying with $length
    token=$(perl -le 'print "x"x'$times)
    result=$(curl -sLw '%{http_code}' -o /dev/null "${url}${token}")

    if [[ $result == 200 ]]; then
        if [[ $ok == $times ]]; then
            echo "max length is $length"
            break
        fi
        ok=$times
        times=$((times+1024))
    else
        times=$(((times+ok)/2))
    fi
done

回答by onlyme

The default limit for the length of the request line is 8192 bytes = 8* 1024. It you want to change the limit, you have to add or update in your tomcat server.xml the attribut maxHttpHeaderSize.

请求行长度的默认限制是 8192 字节 = 8* 1024。如果你想改变这个限制,你必须在你的 tomcat server.xml 中添加或更新属性 maxHttpHeaderSize。

as:

作为:

<Connector port="8080" maxHttpHeaderSize="65536" protocol="HTTP/1.1" ... />

In this example I set the limite to 65536 bytes= 64*1024.

在此示例中,我将限制设置为 65536 字节 = 64*1024。

Hope this will help.

希望这会有所帮助。