nginx 如何禁止运行php
2022-12-02 09:01:16
157
{{single.collect_count}}

nginx禁止运行php的设置方法:首先找到server配置段;然后在server配置段中增加配置“location ~* ^/uploads/.*\.(php|php5)${deny all;}”即可。

php入门到就业线上直播课:进入学习
Apipost = Postman + Swagger + Mock + Jmeter 超好用的API调试工具:点击使用

推荐:《PHP视频教程

Nginx下禁止指定目录运行PHP脚本

Nginx更简单,直接通过location条件匹配定位后进行权限禁止。

在server配置段中增加如下的配置

如果是单个目录

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生效。

以上就是nginx 如何禁止运行php的详细内容,更多请关注php中文网其它相关文章!

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}