06 Location詳解之精準匹配

2021-09-02 20:26:03 字數 1141 閱讀 5091

location 有」定位」的意思, 根據uri來進行不同的定位。

在虛擬主機的配置中,是必不可少的,location可以把**的不同部分,定位到不同的處理方式上。

比如, 碰到.php, 如何呼叫php直譯器? --這時就需要location

location [=|~|~*|^~] patt {}

location = patt {} [精準匹配]

location patt{}  [一般匹配]

location ~ patt{} [正則匹配]

如果訪問 ,定位流程就是

1、精準匹配中 「/」,得到index頁為index.htm

2、再次訪問/index.htm,此次內部轉跳uri已經是「/index.htm",根目錄為/usr/local/nginx/html/

3、最終結果訪問了/usr/local/nginx/html/index.htm

#首先匹配 =,其次匹配^~, 其次是按檔案中順序的正則匹配,最後是交給 / 通用匹配.當有匹配成功時候,停止匹配,按當前匹配規則處理請求

[root@tiejiang nginx]# cat /var/www/html/index.htm          #先找乙個測試頁面放在/var/www/html目錄下

wecome to z.com:8080 admin panel

如果訪問  #定位流程就是

1、精準匹配中 「/」,得到index頁為index.htm

2、再次訪問/index.htm,此次內部轉跳uri已經是「/index.htm",根目錄為/usr/local/nginx/html/

3、最終結果訪問了/usr/local/nginx/html/index.htm

[root@tiejiang nginx]# vim conf/nginx.conf

location =/

location /

location /

nginx的location配置詳解

語法規則 location uri 開頭表示精確匹配 開頭表示uri以某個常規字串開頭,理解為匹配 url路徑即可。nginx不對url做編碼,因此請求為 static 20 aa,可以被規則 static aa匹配到 注意是空格 開頭表示區分大小寫的正則匹配 開頭表示不區分大小寫的正則匹配 和 分...

window的location物件詳解

開啟google瀏覽器,調出除錯工具,在console一欄中輸入window.location,出現如圖所示 包含location的多個屬性 接下來以 為例子,介紹一下location的常用屬性 結果為 結果為 http 結果為 www.myurl.com 8866 結果為 www.myurl.co...

Nginx詳解Location匹配規則

本文我們來給大家詳細介紹下nginx中的核心配置檔案中的location匹配規則。location會嘗試根據使用者請求中的uri來匹配上面的 uri表示式,如果可以匹配,就選擇location 塊中的配置來處理使用者請求。當然,匹配方式是多樣的,下面介紹location的匹配規則。語法 locati...