您的位置:首頁技術文章
文章詳情頁

Nginx中root與alias區別講解

瀏覽:131日期:2023-03-13 15:37:37
目錄
  • 項目結構
  • 測試
  • 總結

Nginx中配置文件路徑有兩種方式,一種是root一種是alias,那么兩種有什么區別呢,下面請跟我

Nginx中配置文件路徑有兩種方式,一種是root一種是alias,那么兩種有什么區別呢,下面請跟我一起正確的使用rootalias

首先還是先說下他倆的區別,主要是對URI部分處理的不同,如下:

項目結構

Nginx 目錄結構如下:html下為部署的前端項目頁面,分別為zuiyutest,下面我將通過使用rootalias來訪問

nginx
    --conf
    --logs
    --html
      --zuiyu
--index.html
--static
      --test
--index.html
--static

測試

訪問zuiyu項目

  location /zuiyu {
    root html;
    index index.html;
  } 
  location /zuiyu {
    alias html/zuiyu;
    index index.html;
  } 

訪問test項目

 location /test {
    root html;
    index index.html;
  } 
  location /test {
    alias html/test;
    index index.html;
  } 

總結

通過上面兩個小例子,相信大家也已經看出來rootalias的區別了,不錯alias就是別名,也就是使用alias配置項目地址的時候,可以直接配置到訪問的項目文件夾,而使用root配置時,Nginx 會在的默認部署路徑html下找到匹配uri中的文件夾,然后在該文件夾下查找index.html

到此這篇關于Nginx中root與alias區別的文章就介紹到這了,更多相關Nginx中root與alias區別內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!

標簽: Nginx
国产综合久久一区二区三区