php 请求的实体太大

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8896644/
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-08-26 05:44:50  来源:igfitidea点击:

Request Entity Too Large

configurationweb-hostingphp

提问by Oleksandr IY

I get this message,

我收到这条消息,

Request Entity Too Large
The requested resource
/index.php
does not allow request data with POST requests, or the amount of data provided in the request exceeds the capacity limit. 

I set

我设置

php_value post_max_size 50M
php_value upload_max_filesize 50M

in .htaccessbut not helped

.htaccess但没有帮助

How to overcome this?

如何克服这一点?

Thanks

谢谢

采纳答案by Sk8erPeter

After you are over the raising of PHP's memory_limit, post_max_sizeand upload_max_filesize, I would like to recommend you some articles related to the topic, maybe one of them solves the problem.

在你对 PHP 的memory_limit,post_max_size和的培养结束后upload_max_filesize,我想向你推荐一些与该主题相关的文章,也许其中一篇可以解决问题。

I found this post on Server Fault:
https://serverfault.com/questions/79741/php-apache-post-limit/79745#79745

我在服务器故障上找到了这篇文章:https:
//serverfault.com/questions/79741/php-apache-post-limit/79745#79745

  • sybreonsuggests to double-check the Content-Length, and - citing - "ensure that you are directly connecting to Apache and not through either a proxy or a reverse-proxy. Some reverse-proxies place a cap on the maximum size of a request as a sort of security measure. So, you may want to check that as well as your Apache logs to ensure that nothing else is going on."

  • sybreon also posted this link: Apache 413 error problems.
    The following is only applicable if you have mod_sslmodule turned onin Apache. (Otherwise this setting can cause a server crash.)
    Citing the article:
    "I was using Apache SSL client certificates, which have a limit of 128K, and if re-negotiation has to happen, a larger POST will fail.
    This Bugzilla postinghad the clues - You have to set the following as DEFAULTS for your SSL server, not just the directory.

    SSLVerifyClient require
    

    Otherwise it forces a renegotiation of some sort, and fails with a 413 error."

  • The previous article also mentioned the LimitRequestBodydirective.
    A guy says here that the appropriate setting of this directive solved his problem..

  • sybreon建议仔细检查Content-Length,并引用 - “确保您直接连接到 Apache,而不是通过代理或反向代理。一些反向代理将请求的最大大小设置为一种上限安全措施。因此,您可能需要检查它以及您的 Apache 日志,以确保没有其他事情发生。”

  • sybreon 还发布了此链接:Apache 413 错误问题
    以下只适用,如果你有mod_ssl的开启模块在Apache中。(否则这个设置会导致服务器崩溃。)
    引用文章:
    “我使用的是 Apache SSL 客户端证书,它有 128K 的限制,如果必须重新协商,更大的 POST 将失败。
    这个 Bugzilla 帖子有线索 - 您必须将以下内容设置为 SSL 服务器的默认值,而不仅仅是目录。

    SSLVerifyClient require
    

    否则,它会强制进行某种形式的重新协商,并因 413 错误而失败。”

  • 上一篇文章也提到了LimitRequestBody指令。
    一个人在这里说这个指令的适当设置解决了他的问题。.

I hope one of these settings solves this problem!

我希望这些设置之一可以解决这个问题!

回答by duskstriker

The only thing that would work for me was to tune up the SSL Buffer Size. You can set this by...

唯一对我有用的是调整 SSL 缓冲区大小。您可以通过...

<Directory /my/blah/blah>
...
  # Set this to something big...
  SSLRenegBufferSize 10486000
...
</Directory>

...and then just restart Apache for the change to take effect. (Found this at: http://forum.joomla.org/viewtopic.php?p=2085574)

...然后只需重新启动 Apache 即可使更改生效。(在:http: //forum.joomla.org/viewtopic.php?p=2085574找到这个)

回答by AnkitK

My server is Apache. It was mod_security module which was preventing post of large data approximately 171 KB. I did below configurations in mod_security.conf

我的服务器是 Apache。是 mod_security 模块,它阻止了大约 171 KB 的大数据的发布。我在 mod_security.conf 中做了以下配置

SecRequestBodyNoFilesLimit 10486000
SecRequestBodyInMemoryLimit 10486000

回答by Shane

If max_post_upload and max_file_upload in PHP has been set, and there is a setting in Apache2.conf or ModSec config files of LimitRequestBody set high enough

如果PHP中的max_post_upload和max_file_upload已经设置,并且在Apache2.conf或者LimitRequestBody的ModSec配置文件中设置的足够高

then possibly a .htaccess file will work.

那么 .htaccess 文件可能会起作用。

  1. Go to the directory with the upload php file in it ( the file or page throwing the error.)
  1. 转到包含上传 php 文件的目录(抛出错误的文件或页面。)

2 . Make or edit .htaccess

2 . 制作或编辑 .htaccess

3 . Edit or create a line with LimitRequestBody 20971520 in it.

3 . 编辑或创建一行,其中包含 LimitRequestBody 20971520。

  1. Save the .htaccess. Set permissions. ( 644 and apache owner)

  2. Possibly restart apache.

  1. 保存 .htaccess。设置权限。( 644 和 apache 所有者)

  2. 可能重启apache。

Tada . Hopefully fixed.

多田。希望修复。

This setting sets that limit for this folder only - which is one way to avoid a global setting in php and apache which makes you open to large packet / load DOS attacks.

此设置仅为此文件夹设置限制 - 这是避免 php 和 apache 中的全局设置的一种方法,该设置使您容易受到大数据包/加载 DOS 攻击。

LimitRequestBody 0 gives you unlimited uploads.

LimitRequestBody 0 为您提供无限上传。

回答by Sumant Shanbag

I was struggling with this 413 - Request entity too large problem for last day or so, as I was trying to upload farely large (in MBs) images to the server.

我在最后一天左右为这个 413 - Request entity too large 问题苦苦挣扎,因为我试图将非常大(以 MB 为单位)的图像上传到服务器。

My setup is apache (227) proxying requests to jboss eap (6.4.20) server for accessing rest endpoints.

我的设置是 apache (227) 将请求代理到 jboss eap (6.4.20) 服务器以访问其余端点。

2 Things worked for me.

2 事情对我有用。

  1. Make SSLVerifyClient required at the virtual host level. This means all the resources need a valid client cert presented to be served. This was not an option for me as all the resources except /api should NOT be mutual auth protected. So, while it worked, this was not an option for me.

  2. I removed the global level SSLVerifyClient required and kept it 'optional'. I re enabled required option only on <Location /api>...</Location>. Trick was to have the SSL renegotiation happen only after a certain threshold is reached - which would be our desired upload file size.

  3. So, finally it turned out that I had to enable 'SSLRenegBufferSize' setting on a specific LocationMatch as follows:

    <LocationMatch ^/api/v1/path/(.*)/to/(.*)/resource/endpoint$>
    SSLRenegBufferSize 5242880 #allow upto 5MB for files to come through </LocationMatch>

  1. 使 SSLVerifyClient 在虚拟主机级别成为必需。这意味着所有资源都需要提供有效的客户端证书才能提供服务。这对我来说不是一个选择,因为除 /api 之外的所有资源都不应受到相互身份验证保护。所以,虽然它有效,但这对我来说不是一个选择。

  2. 我删除了所需的全局级别 SSLVerifyClient 并将其保留为“可选”。我仅在<Location /api>...</Location>. 诀窍是仅在达到某个阈值后才进行 SSL 重新协商 - 这将是我们所需的上传文件大小。

  3. 所以,最后发现我必须在特定的 LocationMatch 上启用“SSLRenegBufferSize”设置,如下所示:

    <LocationMatch ^/api/v1/path/(.*)/to/(.*)/resource/endpoint$>
    SSLRenegBufferSize 5242880 #allow upto 5MB for files to come through </LocationMatch>

(.*) in the case above represents my path params in the endpoint. Hope this helps.

(.*) 在上面的例子中代表我在端点中的路径参数。希望这可以帮助。