入力ファイルを含む 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 構成ファイルには、サーバー プロバイダーのみが編集できるという大きな警告があるため、連絡しています。
何が起こったのかお知らせします。
[解決済み]
Apache モジュール mod_security には、デフォルトで 60kb のアップロード制限があるため、これより大きなアップロードを行うと 403 エラー コードがスローされます。
modsec.conf はサーバー プロバイダーのみが編集できるため、次の行をすべてのルート .htaccess に追加します。
SecFilterEngine Off
これにより、一般的に mod_security フィルターがオフになりました。