本文摘自PHP中文网,作者V,侵删。
nginx禁止指定目录运行php脚本的方法是:直接通过location条件匹配定位后进行权限禁止即可,如【location ~* ^/uploads/.*\.(php|php5)${deny all;}】。

直接通过location条件匹配定位后进行权限禁止。
(学习视频推荐:java课程)
在server配置段中增加如下的配置
如果是单个目录
1 2 3 4 5 6 7 | location ~* ^/uploads/.*\.(php|php5)$
{
deny all;
}
|
如果是多个目录
1 2 3 4 5 6 7 | location ~* ^/(attachments|uploads)/.*\.(php|php5)$
{
deny all;
}
|
注意:这段配置文件一定要放在下面配置的前面才可以生效。
1 2 3 4 5 6 7 8 9 10 11 | location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
|
完整的配置示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | location ~ /mm/(data|uploads|templets)/*.(php)$ {
deny all;
}
location ~ .php$ {
try_files $uri /404.html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
|
配置完后需要重启Nginx生效。
相关推荐:php培训
以上就是nginx禁止指定目录运行php脚本的方法是什么的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
nginx配置文件实例详解
利用php序列化和反序列化的语法差异绕过防护
如何在mac上配置apache和php
apache nginx优缺点
linux执行php文件结果怎么看
centos6.8如何安装php
linux无法打开目录提示权限不够
centos 6.5 php扩展怎么安装
linux如何查看nginx是否启动
linux下设置nginx开机自启的方法
更多相关阅读请进入《nginx》频道 >>
转载请注明出处:木庄网络博客 » nginx禁止指定目录运行php脚本的方法是什么