当用户在我的服务器上传非常大的文件时,我想生成一个“Request Entity Too Large”错误。 用mod-php ,这很简单:
<FilesMatch "^(upload|replace)$"> LimitRequestBody 3000000 </FilesMatch>
用php-fpm ,我尝试了“
<LocationMatch "^/(upload|replace)$"> LimitRequestBody 3000000 </LocationMatch>
但是,它没有工作。 接下来,我尝试在VirtualHost设置代理环境variables:
SetEnv proxy-sendchunked ProxyPassMatch ^/([^\.]+)$ fcgi://127.0.0.1:9000${docroot}/$1
它也没有工作。 谁能告诉我如何做到这一点? 谢谢。
按照rjewell的build议,你需要在你的apache代理上configurationmod_security 。 将以下指令添加到您应该保护的VirtualHost中:
# Enable request processing SecRuleEngine On # enable inspection of request bodies SecRequestBodyAccess On # set actual request size limit SecRequestBodyLimit 3000000 # actually generate an HTTP error, instead of truncating SecRequestBodyLimitAction Reject # Avoid big request bodies that do not try to upload files SecRequestBodyNoFilesLimit 1048576 # tune memory usage SecRequestBodyInMemoryLimit 131072
你可以阅读关于mod_security引用的指令。
根据您的使用情况,请考虑以下几点: