本文摘自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 反向代理多个 docker 容器
nginx哪个版本性能好
如何修改nginx服务的默认端口
nginx配置支持php-fpm
nginx如何实现跳转到指定接口的功能
nginx怎么配置负载均衡
nginx和apache是什么
nginx和lvs区别
centos如何完全卸载php
nginx缓存cache有哪几种方法
更多相关阅读请进入《nginx》频道 >>
转载请注明出处:木庄网络博客 » nginx禁止指定目录运行php脚本的方法是什么