模块ngx_http_index_module

219 阅读1分钟

ngx_http_index_module模块处理以(‘/’)结尾的请求。此类请求也可以被ngx_http_autoindex_modulengx_http_random_index_module模块处理

配置例子

// location: (文件)定位
location / {
    index index.$geo.html index.html;
}

指令

语法:index file ...;
默认:index index.html;
运行环境/上下文context:httpserverlocation

context解释,可以理解为作用域,可以理解为{}, 配置例子就是在locations这个context下使用的改语法,类似的改语法也可以用在 http中,server中

定义那些/个文件做为index(相当于一个入口),file 书写可以包含变量,文件会被指定的规则检查。 参数列表的最后一个成员可以写成一个带有绝对路径的文件。例子:

index index.$geo.html index.0.html /index.html;

注意使用一份index文件会产生一个内部跳转,并且请求req可以在不同的location中被处理。例如,接下来的配置:

location = / {
    index index.html;
}

location / {
    ...
}

“/” 请求实际上将作为“/index.html”在第二个location中被处理.