Nginx - 參數配置 tri_files $uri
Published in:2023-02-19 | category: Web

進行內部重定向 URI 的 nginx 參數



按指定順序檢查文件是否存在,並使用第一個找到的文件進行請求處理



配置

try_files $uri  $uri/ /index.html;

$uri 這個是 nginx 的一個變量,存放著用戶訪問的地址


EX: http://www.xxx.com/index.html 那麼 $uri 就是 /index.html



$uri/ 代表訪問的是一個目錄


EX: http://www.xxx.com/hello/test/ 那麼 $uri/ 就是 /hello/test/



比如用戶訪問這個網地址 http://www.xxx.com/test.html

try_files 首先會判斷他是文件,還是一個目錄,結果發現他是文件,與第一個參數 $uri 變量匹配

然後去到網站目錄下去查找 test.html 文件是否存在,如果存在直接讀取返回。如果不存在就跳去匹配 $uri/

如果 $uri/ 不存在則匹配原路徑底下 /index.html




Prev:
Windows - 安裝影片下載工具 yt-dlp 及 Chocolatey
Next:
GCP - Cloud Functions 部屬 LINE BOT + OpenAI