Nginx默認(rèn)location?index設(shè)置網(wǎng)站的默認(rèn)首頁方法詳解
/斜杠代表location定位的路徑,路徑當(dāng)中最重要的字段就是root。
root默認(rèn)值就是html,這個就是nginx安裝路徑下面的html文件夾作為root的路徑。默認(rèn)不配置就是root下面的內(nèi)容,index指定了主頁的內(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指令是去指定首頁。
root你這里可以更改為自己想要設(shè)置的目錄,并且它的相對路徑是在nginx的安裝路徑下面。
如果你需要寫絕對路徑,那么前面加入斜杠/nginx/。
還有一點就是index后面其實默認(rèn)只有一個配置index.html,另外一個Index.htm是不生效的。這個主頁你可以自己配置。
location / { root /usr/local/nginx/html; index index.html index.htm; }
實際當(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)前瀏覽器已登錄賬戶,需自動跳轉(zhuǎn)到主頁 if(document.cookie && document.cookie.indexOf('_bank_token') != -1) { window.location.href = 'app.html?v=ebba';
Nginx index:首頁處理
HTTP 請求經(jīng)過一系列的請求流程處理后,最終將讀取數(shù)據(jù)并把數(shù)據(jù)內(nèi)容返回給用戶。當(dāng)用戶請求沒有明確指定請求的文件名稱時,Nginx 會根據(jù)設(shè)定返回默認(rèn)數(shù)據(jù),實現(xiàn)這一功能包含 ngx_http_index_module、ngx_http_random_index_module、ngx_http_autoindex_module 這 3 個模塊。
常用的首頁處理配置指令如下面表格中所示。
配置樣例如下:
location / { index index.$geo.html index.html; }
指令值為多個文件時,會按照從左到右的順序依次查找,找到對應(yīng)文件后將結(jié)束查找。
總結(jié)
到此這篇關(guān)于Nginx默認(rèn)location index設(shè)置網(wǎng)站的默認(rèn)首頁的文章就介紹到這了,更多相關(guān)Nginx index網(wǎng)站默認(rèn)首頁內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Nginx設(shè)置404錯誤頁面跳轉(zhuǎn)的幾種方法總結(jié)
一個網(wǎng)站項目,肯定是避免不了404頁面的,通常使用Nginx作為Web服務(wù)器時,有些相關(guān)配置方法,下面小編給大家?guī)砹薔ginx實現(xiàn)404頁面的幾種方法,感興趣的朋友一起看看吧2024-03-03Dockerfile打包nginx鏡像的實現(xiàn)步驟
本文主要介紹了Dockerfile打包nginx鏡像的實現(xiàn)步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-10-10Nginx服務(wù)器屏蔽與禁止屏蔽網(wǎng)絡(luò)爬蟲的方法
今天小編就為大家分享一篇關(guān)于Nginx服務(wù)器屏蔽與禁止屏蔽網(wǎng)絡(luò)爬蟲的方法,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-03-03添加Nginx代理配置只允許內(nèi)部IP訪問的實現(xiàn)方法
在本篇文章里小編給大家整理的是一篇關(guān)于添加Nginx代理配置只允許內(nèi)部IP訪問的實現(xiàn)方法的文章,有需要的朋友們可以學(xué)習(xí)下。2019-10-10nginx服務(wù)器實現(xiàn)上傳下載文件的實例代碼
這篇文章主要介紹了nginx服務(wù)器實現(xiàn)上傳下載文件的實例代碼,本文通過代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-02-02