Apache错误:文件名太长:无法映射GET

And*_*ill 8 javascript apache

我们最近开始在apache日志中看到一个新错误:

[Wed Mar 16 08:32:59 2011] [error] [client 10.40.1.2] (36)File name too long: Cannot map GET /static/app/js <..lots of javascript...>
Run Code Online (Sandbox Code Playgroud)

看起来好像来自页面的JavaScript正在向服务器发送请求.然而,目前还不清楚这将如何发生.从搜索t'internet,看起来像某些wordpress插件已发生这种事情,但没有太多其他信息.

关于环境的注意事项:客户端使用在英国Citrix瘦客户机上运行的IE8.网络服务器距离1700公里,因此存在一些延迟.该网站大量使用AJAX和大型cookie.

有人可以建议如何调试这个问题吗?

谢谢

安德鲁

小智 6

我也得到了这个,使用PHP框架,允许格式化的URL

index.php?controller=doohickey&id=z61
Run Code Online (Sandbox Code Playgroud)

可以改写为

index.php/controller/doohickey/z61
Run Code Online (Sandbox Code Playgroud)

以及框架代码中的正则表达式.

错误看起来像(/ var/log/apache/error_log):

GET /index.php/accounts_badoink/confirmaction/WUW%253DWBW%25253DV0tXPWM3Nzc1....
Run Code Online (Sandbox Code Playgroud)

- >在这种情况下,apache将文件名解析为

/index.php/accounts_badoink/confirmaction/WUW%253DWBW%25253DV0tXPWM3Nzc1....
Run Code Online (Sandbox Code Playgroud)

(我正在序列化一个对象状态并传递它).

我必须将此(至少带有长附加序列化对象的URL)重写为更习惯的样式:

  GET /index.php?controller=accounts_badoink&confirmaction=WUW%253DWBW%25253DV0tXPWM3Nzc1....
Run Code Online (Sandbox Code Playgroud)

- >在这种情况下,Apache正在解析文件名为 index.php

简而言之,重写您的URL并?尽早包含一个,以将数据作为CGI样式参数而不是路径元素传递.

strace -p $PID &为每个Apache进程ID(如报告所示pidof apache2):

# pidof apache2 | tr ' ' '\n' | grep -v 21561 | sed "s|\(.*\)|strace -p \1 \&|g" | sh -
Run Code Online (Sandbox Code Playgroud)

完成 :

# kill -HUP `pidof strace`
Run Code Online (Sandbox Code Playgroud)

并查看apache2的内核调用:

accept(3, {sa_family=AF_INET, sin_port=htons(38985), sin_addr=inet_addr("127.0.0.1")}, [16]) = 13
fcntl(13, F_GETFD)                      = 0
fcntl(13, F_SETFD, FD_CLOEXEC)          = 0
fcntl(13, F_GETFL)                      = 0x2 (flags O_RDWR)
fcntl(13, F_SETFL, O_RDWR|O_NONBLOCK)   = 0
read(13, "GET /newregcon/index.php/account"..., 8000) = 4949
write(2, "[Wed May 11 15:39:36 2011] [erro"..., 4451) = 4451
writev(13, [{"HTTP/1.1 403 Forbidden\r\nDate: We"..., 219}, {"<!DOCTYPE HTML PUBLIC \"-//IETF//"..., 4610}], 2) = 4829
Run Code Online (Sandbox Code Playgroud)

由于这些系统调用没有返回错误(例如'... = -1'),我下载了apache2源代码,并发现:

Grep为"无法映射":

server/core.c

3489:AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r)
3490:{

3520:        if ((rv = apr_filepath_merge(&r->filename, conf->ap_document_root, path,
3521:                                     APR_FILEPATH_TRUENAME
3522:                                   | APR_FILEPATH_SECUREROOT, r->pool))
3523:                    != APR_SUCCESS) {
3524:            ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
3525:                         "Cannot map %s to file", r->the_request);
3526:            return HTTP_FORBIDDEN;
3527:        }
Run Code Online (Sandbox Code Playgroud)

寻找apr_filepath_merge......

srclib/apr/file_io/unix/filepath.c

81:APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath,
82:                                             const char *rootpath,
83:                                             const char *addpath,
84:                                             apr_int32_t flags,
85:                                             apr_pool_t *p)
86:{
87:    char *path;
88:    apr_size_t rootlen; /* is the length of the src rootpath */
89:    apr_size_t maxlen;  /* maximum total path length */

149:    rootlen = strlen(rootpath);
150:    maxlen = rootlen + strlen(addpath) + 4; /* 4 for slashes at start, after
151:                                             * root, and at end, plus trailing
152:                                             * null */
153:    if (maxlen > APR_PATH_MAX) {
154:        return APR_ENAMETOOLONG;
155:    }
Run Code Online (Sandbox Code Playgroud)

APR_PATH_MAX...

Netware的

./srclib/apr/include/apr.hnw:424:#define APR_PATH_MAX PATH_MAX
Run Code Online (Sandbox Code Playgroud)

WIN32

./srclib/apr/include/apr.hw:584:#define APR_PATH_MAX 8192
Run Code Online (Sandbox Code Playgroud)

./srclib/apr/include/apr.h.in

/* header files for PATH_MAX, _POSIX_PATH_MAX */
#if APR_HAVE_LIMITS_H
#include <limits.h>
Run Code Online (Sandbox Code Playgroud)

/usr/src/linux-headers-2.6.35-28/include/linux/limits.h

#define PATH_MAX        4096    /* # chars in a path name including nul */
Run Code Online (Sandbox Code Playgroud)