nginx的RemoveHandler
在我的网站上,用户可以上传他们的文件,并有一个简短的文件url。 在此之前,我使用ApacheWebServer,但现在我想切换到nginx 在apache中,我使用此代码段删除了文件上载到的某些目录的php处理程序:nginx的RemoveHandler,nginx,webserver,debian,Nginx,Webserver,Debian,在我的网站上,用户可以上传他们的文件,并有一个简短的文件url。 在此之前,我使用ApacheWebServer,但现在我想切换到nginx 在apache中,我使用此代码段删除了文件上载到的某些目录的php处理程序: <Directory /var/www/unkown-user-data/uploads> RemoveHandler .php .phtml .php3 .php5 RemoveType .php .phtml .php3 .php5 php_flag engine
<Directory /var/www/unkown-user-data/uploads>
RemoveHandler .php .phtml .php3 .php5
RemoveType .php .phtml .php3 .php5
php_flag engine off
AddHandler default-handler .php
</Directory>
RemoveHandler.php.phtml.php3.php5
删除type.php.phtml.php3.php5
php_标志引擎关闭
AddHandler default handler.php
但是现在,我应该如何在nginx Web服务器上执行此操作?nginx没有removehandler指令。将位置块添加到服务器不同类型的请求 我假设uploads文件夹可能有.php.phtml.php3.php5文件,当从该文件夹请求时,您不希望执行这些文件。以下是我的建议:
location ^~ /uploads/ {
root /var/www/unkown-user-data;
expires max;
}
注意:“^~”很重要(它意味着比regex“~”块具有更高的优先级)。否则,一个正则表达式位置块,例如
location ~ \.php$ {
...
}
将首先匹配,php脚本将被错误执行。以下是nginx wiki中的匹配顺序:
Nginx没有removehandler指令。将位置块添加到服务器不同类型的请求 我假设uploads文件夹可能有.php.phtml.php3.php5文件,当从该文件夹请求时,您不希望执行这些文件。以下是我的建议:
location ^~ /uploads/ {
root /var/www/unkown-user-data;
expires max;
}
注意:“^~”很重要(它意味着比regex“~”块具有更高的优先级)。否则,一个正则表达式位置块,例如
location ~ \.php$ {
...
}
将首先匹配,php脚本将被错误执行。以下是nginx wiki中的匹配顺序: