本文摘自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四层负载均衡配置
探讨openresty和nginx的共享内存区使用物理内存资源(或 ram)?
linux服务器如何安装nginx
apache nginx优缺点
linux系统怎么搭建php网站
在centos下kanglephp怎么安装swoole扩展
centos 安装php mysql扩展
nginx实现负载均衡有哪几个模式
docker怎么安装nginx
nginx反向代理websocket配置
更多相关阅读请进入《nginx》频道 >>
转载请注明出处:木庄网络博客 » nginx禁止指定目录运行php脚本的方法是什么