【问题标题】:Setting up nginx to redirect to the root of the domain on directory browsing设置 nginx 在目录浏览时重定向到域的根目录
【发布时间】:2020-07-08 13:09:35
【问题描述】:

如果用户尝试浏览任何没有 index.php 或 index.html 的目录,我们可以设置 nginx 重定向到我们域的根目录吗?我的 conf 文件中有这个,但现在它似乎阻止了有效的页面访问:

location /* {
    deny all;
    return 301 /;
}

【问题讨论】:

    标签: nginx configuration root


    【解决方案1】:

    默认的 nginx 行为是在此类目录上抛出 403 Forbidden 除非您的配置中有 autoindex on; 指令或使用自定义 try_files 指令更改默认行为。您可以做的最简单的事情是通过重定向到您的站点根 URI 来覆盖此错误:

    error_page 403 =301 /;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-09
      • 1970-01-01
      • 2017-06-26
      • 2013-09-12
      • 2020-11-04
      • 1970-01-01
      • 2013-04-09
      • 1970-01-01
      相关资源
      最近更新 更多