/斜杠代表location定位的路徑,路徑當(dāng)中最重要的字段就是root。
root默認(rèn)值就是html,這個(gè)就是nginx安裝路徑下面的html文件夾作為root的路徑。默認(rèn)不配置就是root下面的內(nèi)容,index指定了主頁(yè)的內(nèi)容。
[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斜杠表示服務(wù)的根目錄,這里index指令是去指定首頁(yè)。?
root你這里可以更改為自己想要設(shè)置的目錄,并且它的相對(duì)路徑是在nginx的安裝路徑下面。
如果你需要寫(xiě)絕對(duì)路徑,那么前面加入斜杠/nginx/。
還有一點(diǎn)就是index后面其實(shí)默認(rèn)只有一個(gè)配置index.html,另外一個(gè)Index.htm是不生效的。這個(gè)主頁(yè)你可以自己配置。
location / {
root /usr/local/nginx/html;
index index.html index.htm;
}
實(shí)際當(dāng)中的配置
[www@12-116-efx-simulation estage-front]$ cat /application/nginx/conf/conf.d/estage-front.conf
server {
listen 7080;
server_name _;
location / {
root /data/app/estage-front/;
index login.html;
}
}
[root@12-116-efx-simulation ~]# ls -l /data/app/estage-front/
總用量 56
-rw-r--r--. 1 www www 5480 9月 16 11:09 app.html
drwxr-xr-x. 3 www www 184 9月 16 11:09 bigdata
drwxr-xr-x. 2 www www 4096 9月 16 11:09 defs
drwxr-xr-x. 2 www www 191 9月 16 11:09 extention
-rw-r--r--. 1 www www 7806 9月 16 11:09 get.html
-rw-r--r--. 1 www www 5033 9月 16 11:09 getRiskPDF.html
drwxr-xr-x. 23 www www 8192 9月 16 11:09 iframe
-rw-r--r--. 1 www www 7738 9月 16 11:09 login.html
-rw-r--r--. 1 www www 4460 9月 16 11:09 modifyPwd.html
drwxr-xr-x. 2 www www 24 9月 16 11:09 proxy
drwxr-xr-x. 8 www www 76 9月 16 11:09 static
[www@12-116-efx-simulation estage-front]$ curl 192.168.12.116:7080/login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content ="IE=edge,chrome=1"/>
<title></title>
<script>
// 如果當(dāng)前瀏覽器已登錄賬戶,需自動(dòng)跳轉(zhuǎn)到主頁(yè)
if(document.cookie && document.cookie.indexOf('_bank_token') != -1) {
window.location.href = 'app.html?v=ebba';
Nginx index:首頁(yè)處理
HTTP 請(qǐng)求經(jīng)過(guò)一系列的請(qǐng)求流程處理后,最終將讀取數(shù)據(jù)并把數(shù)據(jù)內(nèi)容返回給用戶。當(dāng)用戶請(qǐng)求沒(méi)有明確指定請(qǐng)求的文件名稱時(shí),Nginx 會(huì)根據(jù)設(shè)定返回默認(rèn)數(shù)據(jù),實(shí)現(xiàn)這一功能包含 ngx_http_index_module、ngx_http_random_index_module、ngx_http_autoindex_module 這 3 個(gè)模塊。
常用的首頁(yè)處理配置指令如下面表格中所示。
配置樣例如下:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-734570.html
location / {
index index.$geo.html index.html;
}
指令值為多個(gè)文件時(shí),會(huì)按照從左到右的順序依次查找,找到對(duì)應(yīng)文件后將結(jié)束查找。?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-734570.html
到了這里,關(guān)于Nginx 默認(rèn)location index設(shè)置網(wǎng)站的默認(rèn)首頁(yè)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!