【发布时间】:2020-07-08 13:09:35
【问题描述】:
如果用户尝试浏览任何没有 index.php 或 index.html 的目录,我们可以设置 nginx 重定向到我们域的根目录吗?我的 conf 文件中有这个,但现在它似乎阻止了有效的页面访问:
location /* {
deny all;
return 301 /;
}
【问题讨论】:
标签: nginx configuration root
如果用户尝试浏览任何没有 index.php 或 index.html 的目录,我们可以设置 nginx 重定向到我们域的根目录吗?我的 conf 文件中有这个,但现在它似乎阻止了有效的页面访问:
location /* {
deny all;
return 301 /;
}
【问题讨论】:
标签: nginx configuration root
默认的 nginx 行为是在此类目录上抛出 403 Forbidden 除非您的配置中有 autoindex on; 指令或使用自定义 try_files 指令更改默认行为。您可以做的最简单的事情是通过重定向到您的站点根 URI 来覆盖此错误:
error_page 403 =301 /;
【讨论】: