[英]Apache 403 Forbidden When Uploading Files
I'm having a strange apache error when I submit a multipart/form-data form with an input file. 我使用输入文件提交多部分/表单数据表单时遇到奇怪的apache错误。 It seems that only happens when I upload files 70kb or bigger.
看来只有在我上传70kb或更大的文件时才会发生。
Here are my php.ini settings: 这是我的php.ini设置:
file_uploads = On
upload_max_filesize = 10M
max_execution_time = 90
max_input_time = 90
memory_limit = 196M
post_max_size = 10M
Here is the HTML in test.php: 这是test.php中的HTML:
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="pdfMagazine" />
<input type="submit" value="Save" name="saveMagazine" />
</form>
And here is the error: 这是错误:
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
Here's some more details about the environment: 以下是有关环境的更多详细信息:
.htaccess
restricting the file upload .htaccess
限制文件上传 Can anyone help me please? 谁能帮我吗?
Thanks in advance. 提前致谢。
[UPDATE] [更新]
It appears that server does have mod_security installed, here is apache raw log: 看来服务器确实安装了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"]
Doing research I found this: 经过研究,我发现:
**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
I did change the php.ini but the modsec configuration file has a big warning that only servers provider can edit it so I'm contacting them. 我确实更改了php.ini,但modsec配置文件有一个大警告,只有服务器提供商才能编辑它,因此我正在与他们联系。
I'll let you know what happend. 我会让你知道发生了什么。
[SOLVED] [解决了]
Apaches module mod_security has a 60kb upload limit by default so any bigger upload will throw a 403 error code. 默认情况下,Apache的mod_security模块的上传限制为60kb,因此任何较大的上传都会引发403错误代码。
As the modsec.conf is only editable by the server provider, I add the following line to every root .htaccess: 由于modsec.conf只能由服务器提供者编辑,因此我将以下行添加到每个根.htaccess中:
SecFilterEngine Off
That turned off the mod_security filter in general. 通常关闭了mod_security过滤器。
Apaches module mod_security has a 60kb upload limit by default so any bigger upload will throw a 403 error code. 默认情况下,Apache的mod_security模块的上传限制为60kb,因此任何较大的上传都会引发403错误代码。
As the modsec.conf is only editable by the server provider, I add the following line to every root .htaccess: 由于modsec.conf只能由服务器提供者编辑,因此我将以下行添加到每个根.htaccess中:
SecFilterEngine Off
That turned off the mod_security filter in general. 通常关闭了mod_security过滤器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.