Skip to content

Commit 8520cd8

Browse files
committed
ops/network-service: index workaround
1 parent 4268903 commit 8520cd8

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

docs/ops/network-service/nginx.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,18 @@ autoindex on;
894894
}
895895
```
896896

897+
不过 `try_files` 的问题是:它没有办法继承到子 `location` 中,这在配置复杂的情况下是难以接受的。因此我们可以有另一个 workaround 方案:`index` 指令的最后一个参数可以是 URI 绝对路径,例如 `index index.html /_dir_handler`。于是我们的配置可以改成:
898+
899+
```nginx
900+
index index.html index.htm /_dir_handler;
901+
902+
location = /_dir_handler {
903+
internal;
904+
# 由于 $uri 已经是 /_dir_handler/,因此只能从 $request_uri 中获取原始请求路径
905+
proxy_pass http://127.0.0.1:1234/$request_uri; # 文件列表程序监听的地址
906+
}
907+
```
908+
897909
有关 `internal` 与 `if` 等相关的介绍,可参考下文的 [Rewrite](#rewrite) 部分。
898910

899911
## 速率、请求与连接数限制 {#limiting}

0 commit comments

Comments
 (0)