原创文章,转载请指明出处并保留原文url地址
本文主要针对nginx的ngx_http_index_module 模块做简单介绍,本文具体包括如下指令:index
ngx_http_index_module模块处理以斜杠(“/”)开头的请求, 类似的请求也可以被ngx_http_autoindex_module和ngx_http_random_index_module模块所处理。
配置日子如下:
location / {
index index.$geo.html index.html;
}
Nginx原文:
The module ngx_http_index_module processes requests ending with the slash character (‘/’). Such requests can also be processed by ngx_http_autoindex_module and ngx_http_random_index_module modules.
Example Configuration
location / {
index index.$geo.html index.html;
}
1. index
syntax: | index file…; |
default: | index index.html; |
context: | http, server, location |
定义被作为index页面(一般式默认页面,就是不输入任何页面地址时, 网站应该打开的页面)的文件。 这个文件名可能包括变量。 文件被按照次序(书写次序, 写在最后最后被检查)进行检查。在文件列表中最后一个内容可以是包括绝对路径的文件(其他的应该是相对路径的文件名称)
例如:
index index.$geo.html index.0.html /index.html;
应当指出的是,使用一个索引文件时,一个内部的重定向被产生,一个请求在多个不同的location中进行处理,例如下面的配置:
location = / {
index index.html;
}
location / {
…
}
请求(“/”)实际上是将在第二位置的location中被处理。(显然例子中有两个location配置, 用户请求过来后nginx会进行匹配, 越精确的匹配越先进行, 首先匹配的是=/的location, 然后在这个里面进行了 配置, 需要获取index.html, 之后这个文件要到哪里去找, 只好到下面的location中去配置的文件中去找。)
Nginx原文:
Defines files that will be used as an index. The file name can contain variables. Files are checked in the specified order. The last element of the list can be a file with an absolute path. Example:
index index.$geo.html index.0.html /index.html;
It should be noted that when using an index file, an internal redirect is made, and request can be processed in a different location. For example, with the following configuration:
location = / {
index index.html;
}
location / {
…
}
a request of “/” will actually be processed in the second location as “/index.html”.