nginx下禁止站点或目录运行php脚本

admin2012-06-15linux51
为了安全起见,我们一般会对上传目录禁止运行php脚本 在apache下面我们可以通过: php_flag engine off 的方式来来禁用目录下文件php执行权限。那么在nginx里面同样可以实现这种方法 这里简单就举个例子 location ^~ /attachments/ { access_log off; } 这样 attachments这个目录 就不会再去跳转给fastcgi去执行php了.这里利用了nginx下location指令的处理顺序优先级特点. 但上面的方法只能算一种技巧,一般不这样设置,正确的方法为: location /upload/ { location ~ .*\.(php)?$ { deny all; } } 而对于多个目录的话,可以一起进行限定: location ~* ^/(attachments|images)/.*\.(php|php5)$ { deny all; }