Nginx 默认的location index设置网站的默认首页

/斜杠代表location定位的路径,路径当中最重要的字段就是root。

root默认值就是html,这个就是nginx安装路径下面的html文件夹作为root的路径。默认不配置就是root下面的内容,index指定了主页的内容。

bash 复制代码
[root@jenkins html]# echo test > test.html
[root@jenkins html]# ls
50x.html  dist  test.html

root@jenkins html]# pwd
/usr/local/nginx/html
[root@jenkins html]# ls
50x.html  dist  test.html
[root@jenkins html]# cat test.html 
test


[root@jenkins ~]# vim /usr/local/nginx/conf/nginx.conf
        location / {
          root html;
          index test.html;
        }

location斜杠表示服务的根目录,这里index指令是去指定首页。

root你这里可以更改为自己想要设置的目录,并且它的相对路径是在nginx的安装路径下面。

如果你需要写绝对路径,那么前面加入斜杠/nginx/。

还有一点就是index后面其实默认只有一个配置index.html,另外一个Index.htm是不生效的。这个主页你可以自己配置。

bash 复制代码
location / {
    root /usr/local/nginx/html;
    index index.html index.htm;
}

Nginx index:首页处理


HTTP 请求经过一系列的请求流程处理后,最终将读取数据并把数据内容返回给用户。当用户请求没有明确指定请求的文件名称时,Nginx 会根据设定返回默认数据,实现这一功能包含 ngx_http_index_module、ngx_http_random_index_module、ngx_http_autoindex_module 这 3 个模块。

常用的首页处理配置指令如下面表格中所示。

配置样例如下:

bash 复制代码
location / {
    index index.$geo.html index.html;
}

指令值为多个文件时,会按照从左到右的顺序依次查找,找到对应文件后将结束查找。

相关推荐
章老师说1 天前
NGINX官方谈Lua风险:这其实是两条网关技术路线之争
运维·nginx·负载均衡·lua·openresty
xixingzhe22 天前
SpringBoot + Nginx 免鉴权接口安全防护方案
运维·nginx·安全
酷炫的水壶2 天前
使用memc-nginx和srcache-nginx模块构建高效透明的缓存机制
运维·nginx·缓存
智商偏低2 天前
Windows Nginx 完整安装 + 启动教程
运维·nginx
oscar9992 天前
3.4 Nginx 负载均衡——动态再平衡的反人性纪律
nginx·github·负载均衡·财富源代码
川石课堂软件测试2 天前
性能测试|Nginx中间件监控与调优
linux·python·nginx·中间件·单元测试·压力测试·harmonyos
m0_740859623 天前
Nginx进行配置文件拆分(以windows解压版为例)
nginx
开发小程序的之朴3 天前
认识安企CMS-安装安企CMS的环境要求
nginx·golang·系统架构
考虑考虑3 天前
nginx配置ssl
运维·后端·nginx
至乐活着3 天前
ELK日志系统从零搭建到实战:Nginx日志采集与可视化全攻略
nginx·elk·elasticsearch·docker·日志系统