nginx禁止指定目录运行php脚本的方法是:直接通过location条件匹配定位后进行权限禁止即可,如【location ~* ^/uploads/.*\.(php|php5)${deny all;}】。
直接通过location条件匹配定位后进行权限禁止。
(学习视频推荐:java课程)
在server配置段中增加如下的配置
如果是单个目录
立即学习“PHP免费学习笔记(深入)”;
location ~* ^/uploads/.*\.(php|php5)$ { deny all; }
如果是多个目录
location ~* ^/(attachments|uploads)/.*\.(php|php5)$ { deny all; }
注意:这段配置文件一定要放在下面配置的前面才可以生效。
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; }
完整的配置示例
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脚本的方法是什么的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号