【问题标题】:Why do I get HTTP 501 errors for certain requests?为什么某些请求会出现 HTTP 501 错误?
【发布时间】:2015-06-01 20:47:35
【问题描述】:

我为自己编写了一个简单的 web 应用程序,以便能够在我的服务器上编辑文件,当我在一个只允许 http 和 https 端口的地方...

但我遇到了一个奇怪的问题。

通常在我保存文件时会交换这些标头(已删除机密信息):

https://example.com/?

POST /? HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: hu-HU,en-US;q=0.8,hu;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Referer: https://example.com/?path=/home/csirmazd/public_html/[...]/fs/view/login.php&view=preview
Cookie: [...]
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 644
[...]

HTTP/1.1 303 See Other
Date: Sat, 28 Mar 2015 14:57:40 GMT
Server: Apache/2.2.29 (Unix) mod_ssl/2.2.29 OpenSSL/1.0.1e-fips mod_bwlimited/1.4
X-Powered-By: PHP/5.4.36
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: ?path=/home/csirmazd/public_html/[...]/fs/view/login.php&view=preview
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html
----------------------------------------------------------
https://example.com/?path=/home/csirmazd/public_html/[...]/fs/view/login.php&view=preview

GET /?path=/home/csirmazd/public_html/[...]/fs/view/login.php&view=preview HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: hu-HU,en-US;q=0.8,hu;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Referer: https://example.com/?path=/home/csirmazd/public_html/[...]/fs/view/login.php&view=preview
Cookie: [...]
Connection: keep-alive

HTTP/1.1 200 OK
Date: Sat, 28 Mar 2015 14:57:40 GMT
Server: Apache/2.2.29 (Unix) mod_ssl/2.2.29 OpenSSL/1.0.1e-fips mod_bwlimited/1.4
X-Powered-By: PHP/5.4.36
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
----------------------------------------------------------

但是当我尝试保存另一个特定文件,即 dir.php 时,情况有所不同:

https://example.com/?

POST /? HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:36.0) Gecko/20100101 Firefox/36.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: hu-HU,en-US;q=0.8,hu;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Referer: https://example.com/?path=/home/csirmazd/public_html/[...]/fs/view/dir.php&view=preview
Cookie: [...]
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 4604
[...]

HTTP/1.1 501 Method Not Implemented
Date: Sat, 28 Mar 2015 15:03:04 GMT
Server: Apache/2.2.29 (Unix) mod_ssl/2.2.29 OpenSSL/1.0.1e-fips mod_bwlimited/1.4
Allow: TRACE
Content-Length: 458
Connection: close
Content-Type: text/html; charset=iso-8859-1
X-Pad: avoid browser bug
----------------------------------------------------------

而浏览器中的消息是

GET to / not supported.

什么?那为什么它适用于其他一切?

根本不调用底层 PHP 代码。

首先我认为这是一个有问题的 .htaccess。但是如果我记得我禁用了它,在根目录中有一个 RewriteEngine On。所以我认为这不是问题。 (它仍然通过为它调用 index.php 来处理 example.com/。)

我的第二个想法是 POST 请求的最大大小非常小。但我可以毫无问题地编辑更大的文件。

现在我的想法用完了,不知道该去哪里找。

有什么想法吗?

【问题讨论】:

    标签: php apache .htaccess http http-headers


    【解决方案1】:

    问题的根源似乎是托管服务提供商安装的 Apache 服务器上的 ModSecurity 模块。

    作为others had issues with it too on a different site

    所以我尝试了一个实验并将相同的内容发布到一个随机 URI 并得到与以前相同的错误。显然,当您从表单提交代码时,这件事不喜欢。

    所以显而易见的解决方案是将其关闭。

    在我的特殊情况下,我的 cPanel 中没有选项可以关闭它,所以我设法通过 base64 编码客户端的表单内容来绕过它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-19
      • 2016-01-25
      • 1970-01-01
      • 2019-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-31
      相关资源
      最近更新 更多