nginx禁止指定目录运行php脚本的方法是什么


本文摘自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》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...