-
该指令后面可以跟多个文件,用空格隔开;
-
如果包括多个文件,Nginx会根据文件的枚举顺序来检查,直到查找的文件存在;
-
文件可以是相对路径也可以是绝对路径,绝对路径需要放在最后;
-
文件可以使用变量
$
来命名;
index index.$geo.html index.0.html /index.html;
- 该指令拥有默认值,
index index.html ,即,如果没有给出index,默认初始页为index.html
server {
listen 80;
server_name example.org www.example.org;
location / {
root /data/www;
index index.html index.php;
location ~ \.php$ {
root /data/www/test;
上面的例子中,如果你使用example.org或www.example.org直接发起请求,那么首先会访问到“/”的location,结合root与index指令,会先判断/data/www/index.html是否存在,如果不,则接着查看
/data/www/index.php ,如果存在,则使用/index.php发起内部重定向,就像从客户端再一次发起请求一样,Nginx会再一次搜索location,毫无疑问匹配到第二个~ \.php$,从而访问到/data/www/test/index.php。
关注作者公众号,随时了解更多干货!
index
syntax: index file [file…]
default: index index.html
context: http, server, location
Directive determines the file(s) which will be used as the index. It’s possible to use variables in the name of file. The presence of the files is checked in the order of their enumeration. A file with an absolute path can be put at the end. Example using a variable:
index index.$geo.html index.0.html /index.html;
If you want to automatically generate an index from a directory listing, useautoindex on.
详情可见:《HttpIndex模块》《Nginx中文文档》
The ngx_http_index_module module processes requests ending with the slash character (‘/’). Such requests can also be processed by the ngx_http_autoindex_module and ngx_http_random_index_module modules.
Example Configuration
location / {
index index.$geo.html index.html;
Directives
Syntax: index file …;
Default: index index.html;
Context: http,server, location
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 using an index file causes an internal redirect, and the request can be processed in a different location. For example, with the following configuration:
location = / {
index index.html;
location / {
a “/” request will actually be processed in the second location as “/index.html”.
详情可见:《Nginx官方文档》
看到这里你难道还不想吐槽吗?
所以,搞IT,如果你已经入门,请认准《官方文档》《新框架(新工具,语言)从入门到精通的正确姿势》
目录目录完全理解index指令Nginx中文文档Nginx官方文档吐槽完全理解index指令该指令后面可以跟多个文件,用空格隔开;文件可以是相对路径也可以是绝对路径;文件可以使用变量$来命名;该指令拥有默认值,index index.html ,即,如果没有给出index,默认初始页为indexNginx中文文档index...
需要进入nginx的安装目录中的(也可以配置环境变量,在任何目录都可以执行下面的命令),里面有一个nginx脚本文件
2、Nginx配置文件(nginx.conf)
2.1概述
nginx.conf主要由三部分组成
2.2全局块
就是配置文件从头开始到events块之间的内容,比如worker_process, 值越大,可以支持的并发处理量也越多,但是还是和服务器的硬件相关events 块涉及的指令主要影响 Nginx 服务器与用户的网络连接,常用的设置包括是否开启对多 work process下的网络连
1.1 本案例以 centos7 系统作为演示,配置文件在 /etc/nginx/conf.d/test.conf 中,内容如下
server {
listen 8000;
server_name 127.0.0.1;
root /home/cookcyq/web/;
error_page 404 /40x.html;
error_page 500 502 503 504 /50x.ht
上一篇文章写的nginx的基础安装,以及nginx配置文件的整体结构。这篇文章将会一起来看一下nginx中的一个重要属性location,location是放在server里面的,用于匹配访问的域名后的path路径。location匹配的规则很复杂,内容也是非常多,这里只做简单的介绍。
location的匹配规则
location的三种匹配方式
location的匹配规则有三种,分别是精准匹配、普通匹配和正则匹配。下面对三种匹配做一个说明。
http://blog.itcrud.com/2018/12/12
今天继续给大家介绍Linux运维的相关知识,本文主要内容是Nginx主配置文件详解。
一、Nginx location模块简介
二、Nginx location匹配符与匹配优先级
三、Nginx location匹配示例
Nginx的location配置是通过在nginx配置文件中定义location块来实现的。在location块中,您可以配置该路径下的各种请求处理方式。
语法如下:
location [ = | ~ | ~* | ^~ ] uri {
- `=` 号表示精确匹配,即请求路径与location后的uri完全一致时才会使用该location块中的配置。
- `~` 号表示正则匹配,用于匹配大小写敏感的正则表达式。
- `~*` 号表示正则匹配,用于匹配大小写不敏感的正则表达式。
- `^~` 号表示前缀匹配,如果请求路径以location后的uri为前缀,则使用该location块中的配置,并且不再继续匹配其他location。
例如,下面的配置将请求路径为/static/的请求转发到/data/www目录下:
location /static/ {
root /data/www;
更多信息,您可以参考nginx官方文档:http://nginx.org/en/docs/http/ngx_http_core_module.html#location
root cause org.apache.ibatis.ognl.OgnlException: source is null for getProperty(null, "XXX")
45048
解决方案(二)— 将 "http://apache.org/xml/features/disallow-doctype-decl" 设置为“true”时, 不允许使用 DOCTYPE
m0_68032227:
Nginx之坑:完全理解location中的index,配置网站初始页
沧海一声笑·rush:
阿里云服务器使用SSH工具连接不上,并且ping不通,显示连接超时
w1215435751:
mysqld_safe Directory ‘/var/lib/mysql‘ for UNIX socket file don‘t exists.
weixin_52510780:
无法定位程序输入点ucrtbase.terminate于动态链接库api-ms-win-crt-runtime-|1-1-0.dll
m0_50458308: