2013-06-12 75 views
2

當我使用輸入文件提交multipart/form-data表單時,出現奇怪的apache錯誤。似乎只有當我上傳70kb或更大的文件時纔會發生。Apache 403上傳文件時被禁止

這裏是我的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 

這裏的一些更多關於環境的細節:

  • 阿帕奇doesn't已經安裝了mod_security後,there's沒有.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配置文件有一個很大的警告,只有服務器提供商可以編輯它,所以我聯繫他們。

我會讓你知道發生了什麼。

[解決]

阿帕奇模塊mod_security的預設具有60KB上傳限制,所以任何更大的上傳將拋出403錯誤代碼。

由於modsec.conf僅由服務器提供商可編輯的,我下面的行添加到每一根的.htaccess:

SecFilterEngine Off 

這關掉的mod_security過濾器一般。

+0

在/ var/www文件夾和test.php的所有父文件夾上做ls -ltr。把這個信息放在問題中 –

回答

4

默認情況下,Apaches模塊mod_security的上傳限制爲60kb,因此任何更大的上傳都會引發403錯誤代碼。

由於modsec.conf僅由服務器提供商可編輯的,我下面的行添加到每一根的.htaccess:

SecFilterEngine Off 

這關掉的mod_security過濾器一般。