ITPub博客

首页 > IT职业 > IT职场 > linux中nginx下禁止某目录执行php程序

linux中nginx下禁止某目录执行php程序

IT职场 作者:古月雪 时间:2021-09-09 09:15:38 0 删除 编辑

为了安全起见,我们一般会对上传目录禁止运行php脚本
修改nginx.conf配置文件
禁止单目录:

location ~* ^/attachments/.*.(php|php5)$ {deny all;}

禁止多目录:

location ~* ^/(attachments|upload)/.*.(php|php5)$ {deny all;}

需要注意两点:
1、以上的配置文件代码需要放到 location ~ .php{...}上面,如果放到下面是无效的
2、attachments需要写相对路径,不能写绝对路径
3、不要忘记重启nginx呀,service nginx restart

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3711/viewspace-2801438/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-07-09

  • 博文量
    160
  • 访问量
    1173