禁止“ / opt / eds / web / html”的目录索引

时间:2019-12-17 15:28:48

标签: nginx

要配置nginx,如下所示

location ~ "^/[A-Z0-9]{32}" {
 alias /opt/eds/web/html;
 index  index.html index.htm;
}

nginx异常日志

`2019/12/17 23:22:56 [error] 28874#28874: *4 directory index of "/opt/eds/web/html" is forbidden`

但按如下所示修改nginx配置

location /25DE5ADF310211E9BDB874D435BEC0BA {
 alias /opt/eds/web/html;
 index  index.html index.htm;
}

访问没有问题

1 个答案:

答案 0 :(得分:0)

alias与正则表达式location一起使用时,您需要捕获URI的其余部分并将其附加在alias值上。

例如:

location ~ "^/[A-Z0-9]{32}(/.*)?$" {
    alias /opt/eds/web/html$1;
    index  index.html index.htm;
}

有关详细信息,请参见this document