当前位置:论坛首页 > Linux面板 > 求助

【已完成】NGINX 怎么配置ThinkPHP5 只应许入口index.php

发表在 Linux面板2024-1-16 21:18 [复制链接] 2 564

系统版本:

系统:centOS7.9 NGINX:1.16
问题描述:

为了网站更加安全,有这样的需求:

1.网站跟目录,只能访问txt和入口文件index.php,其他的文件一律禁止访问

2.跟目录下子目录 application/ config/ extend/ public/ route/ runtime/ thinkphp /vendor 这些目录下的任何文件禁止被直接访问

3.单独 public 目录 不能直接访问任何(PHP .sh .pl .py)文件,其他的都放开可以访问



使用道具 举报 只看该作者 回复
发表于 2024-1-17 09:58:52 | 显示全部楼层
以下配置仅供参考,请根据自身情况进行调整
1,
  1.     location / {
  2.         index index.php;
  3.         if ($uri !~* ^/(index\.php|robots\.txt)) {
  4.             return 403;
  5.         }
  6.     }
复制代码

2,
  1.     location ~ /(application|config|extend|public|route|runtime|thinkphp|vendor)/ {
  2.         deny all;
  3.         return 403;
  4.     }
复制代码

3,
  1.     location /public {
  2.         location ~* \.(php|sh|pl|py)$ {
  3.             deny all;
  4.         }
复制代码
使用道具 举报 回复 支持 反对
发表于 2024-1-17 13:47:58 | 显示全部楼层
这个是在站点的配置文件 还是在伪静态里进行中配置
使用道具 举报 回复 支持 反对
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

企业版年付运维跟进群

普通问题处理

论坛响应时间:72小时

问题处理方式:排队(仅解答)

工作时间:白班:9:00 - 18:00

紧急问题处理

论坛响应时间:10分钟

问题处理方式:1对1处理(优先)

工作时间:白班:9:00 - 18:00

工作时间:晚班:18:00 - 24:00

立即付费处理
快速回复 返回顶部 返回列表