gpt4 book ai didi

php - Apache 403 禁止上传文件

转载 作者:行者123 更新时间:2023-12-02 01:11:21 27 4
gpt4 key购买 nike

当我提交带有输入文件的 multipart/form-data 表单时,我遇到了一个奇怪的 apache 错误。似乎只有当我上传 70kb 或更大的文件时才会发生。

这是我的 php.ini 设置:

file_uploads = On
upload_max_filesize = 10M
max_execution_time = 90
max_input_time = 90
memory_limit = 196M
post_max_size = 10M

这是 test.php 中的 HTML:

<form action=""  method="POST" enctype="multipart/form-data">
<input type="file" name="pdfMagazine" />
<input type="submit" value="Save" name="saveMagazine" />
</form>

这里是错误:

Forbidden

You don't have permission to access /test.php on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

Apache/2.2.24 (Unix) mod_ssl/2.2.24 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 Server at myserver.com Port 80

这里有一些关于环境的更多细节:

  • Apache 没有安装 mod_security,没有 .htaccess 限制文件上传
  • 日志仅指出存在 403 代码
  • 我试过的test.php权限是755和644
  • 如果没有上传文件,表单提交正常。

谁能帮帮我?

提前致谢。

[更新]

看起来服务器确实安装了 mod_security,这里是 apache 原始日志:

[Wed Jun 12 19:48:01 2013] [error] [client x.x.x.x] mod_security: Access denied with code 403. read_post_payload: Failed to create file "/root/tmp/20130612-194801-190.115.8.74-request_body-deJpho" because 13("Permission denied") [severity "EMERGENCY"] [hostname "myserver.com"] [uri "/test.php"]
[Wed Jun 12 19:48:01 2013] [error] [client x.x.x.x] mod_security: sec_filter_in: Failed to open file "/root/tmp/20130612-194801-190.115.8.74-request_body-deJpho" [hostname "myserver.com"] [uri "/403.shtml"]

做研究我发现了这个:

**Upload tmpdir issues**

Seeing this?

<source lang='php'> [Fri Nov 18 14:49:50 2011] [error] [client 72.52.142.215] mod_security: Access denied with code 406. read_post_payload: Failed to create file "/root/tmp/20111118-144950-72.52.142.215-request_body-xGPNPd" because 13("Permission denied") [severity "EMERGENCY"] [hostname "lakedonpedro.org"] [uri "/wp-cron.php?doing_wp_cron"] [unique_id "TsbhJkg0jtcAACYIFDk"] </source>

This actually happens because PHP's being set to use /root/tmp and the upload tmp dir. Let's set a few things then! Yay!

Make sure these are all set in /usr/local/lib/php.ini (session.save_path will probably already be set)
upload_tmp_dir = /tmp
session.save_path = /tmp

Make sure these are all set in /usr/local/apache/conf/modsec2.user.conf (or the applicable file for your system)
SecUploadDir /tmp
SecTmpDir /tmp

Restart the apachies.
It also seems it has worked adding the above to modsec.conf corrects this issue. per ~awilson

我确实更改了 php.ini,但是 modsec 配置文件有一个很大的警告,只有服务器提供商可以编辑它,所以我正在联系他们。

我会让你知道发生了什么。

[已解决]

默认情况下,Apaches 模块 mod_security 的上传限制为 60kb,因此任何更大的上传都会抛出 403 错误代码。

由于 modsec.conf 只能由服务器提供商编辑,我将以下行添加到每个根 .htaccess:

SecFilterEngine Off

这通常会关闭 mod_security 过滤器。

最佳答案

默认情况下,Apaches 模块 mod_security 的上传限制为 60kb,因此任何更大的上传都会抛出 403 错误代码。

由于 modsec.conf 只能由服务器提供商编辑,我将以下行添加到每个根 .htaccess:

SecFilterEngine Off

这通常关闭了 mod_security 过滤器。

关于php - Apache 403 禁止上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17076893/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com