日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

(5) nginx:location

發布時間:2024/1/23 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 (5) nginx:location 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

location 語法

location 有”定位”的意思, 根據Uri來進行不同的定位.

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

比如, 碰到.php, 如何調用PHP解釋器?? --這時就需要location

location 的語法

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

}

中括號可以不寫任何參數,此時稱為一般匹配

也可以寫參數

因此,大類型可以分為3種

location = patt {} [精準匹配]

location patt{}? [一般匹配]

location ~ patt{} [正則匹配]

?


如何發揮作用?:

首先看有沒有精準匹配,如果有,則停止匹配過程.

location = patt {

???config A

}

如果 $uri ==patt,匹配成功,使用configA

??location = / {

????????????? root?? /var/www/html/;

????????????index? index.htm index.html;

???????}

????????

?location / {

????????????root?? /usr/local/nginx/html;

???????????index? index.html index.htm;

? }

?

如果訪問  http://xxx.com/

定位流程是 

1: 精準匹配中 ”/”?? ,得到index頁為  index.htm

2: 再次訪問 /index.htm , 此次內部轉跳uri已經是”/index.htm” ,

根目錄為/usr/local/nginx/html

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

?


再來看,正則也來參與.

location / {

??????????? root?? /usr/local/nginx/html;

??????????? index? index.html index.htm;

???? ???}

?

location ~ image {

?????????? root /var/www/image;

?????????? index index.html;

}

?

如果我們訪問? http://xx.com/image/logo.png

此時, “/” 與”/image/logo.png”匹配

同時,”image”正則 與”image/logo.png”也能匹配,誰發揮作用?

正則表達式的成果將會使用.

?

圖片真正會訪問 /var/www/image/logo.png

?

?


location / {

????????????root?? /usr/local/nginx/html;

????????????index? index.html index.htm;

????????}

?

location /foo {

???????????root /var/www/html;

????????????index index.html;

}

我們訪問http://xxx.com/foo

?對于uri “/foo”,?? 兩個location的patt,都能匹配他們

即 ‘/’能從左前綴匹配 ‘/foo’, ‘/foo’也能左前綴匹配’/foo’,

此時, 真正訪問 /var/www/html/index.html

原因:’/foo’匹配的更長,因此使用之.;

總結

以上是生活随笔為你收集整理的(5) nginx:location的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。