欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

nginx location中uri的截取的實(shí)現(xiàn)方法

 更新時(shí)間:2019年04月12日 14:51:25   作者:全棧運(yùn)維  
這篇文章主要介紹了nginx location中uri的截取的實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

說(shuō)明:

location 中的 root 和 alias

  • root 指令只是將搜索的根設(shè)置為 root 設(shè)定的目錄,即不會(huì)截?cái)?uri,而是使用原始 uri 跳轉(zhuǎn)該目錄下查找文件
  • aias 指令則會(huì)截?cái)嗥ヅ涞?uri,然后使用 alias 設(shè)定的路徑加上剩余的 uri 作為子路徑進(jìn)行查找

location 中的 proxy_pass 的 uri

如果 proxy_pass 的 url 不帶 uri

  • 如果尾部是"/",則會(huì)截?cái)嗥ヅ涞膗ri
  • 如果尾部不是"/",則不會(huì)截?cái)嗥ヅ涞膗ri

如果proxy_pass的url帶uri,則會(huì)截?cái)嗥ヅ涞膗ri

Examples

location中的 root

root@pts/1 $ ls -ld /data/web/lctest*|awk '{print $NF}'
/data/web/lctest
/data/web/lctest2
/data/web/lctest3
/data/web/lctest4


location /lctest {
  root /data/web/;
}

location /lctest2/ {
  root /data/web/;
}
location /lctest3 {
  root /data/web;
}
location /lctest4/ {
  root /data/web;
}

curl 測(cè)試結(jié)果如下

備注: 瀏覽器輸入的時(shí)候最后面不添加 / , 會(huì)自動(dòng)補(bǔ)上,但是curl 不行

root@pts/1 $ curl http://tapi.xxxx.com/lctest/
hello world

root@pts/1 $ curl http://tapi.xxxx.com/lctest2/
hello world
2

root@pts/1 $ curl http://tapi.xxxx.com/lctest3/
3
hello world

root@pts/1 $ curl http://tapi.xxxx.com/lctest4/
hello world
4

location alias

location /lctest5 {
  alias /data/web/;
}
location /lctest6/ {
  alias /data/web/;
}

location /lctest7 {
  alias /data/web;
}

## 403 /data/web forbidden
location /lctest8/ {
  alias /data/web;
}

curl 測(cè)試結(jié)果如下

curl 'http://tapi.kaishustory.com/lctest5/'
curl 'http://tapi.kaishustory.com/lctest6/'
curl 'http://tapi.kaishustory.com/lctest7/'
結(jié)果都是 /data/web/index.html的輸出

root@pts/1 $ curl 'http://tapi.kaishustory.com/lctest8/'
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body>
</html>

location proxy_pass

#--------proxy_pass配置---------------------
location /t1/ { proxy_pass http://servers; }  #正常,不截?cái)?
location /t2/ { proxy_pass http://servers/; }  #正常,截?cái)?
location /t3 { proxy_pass http://servers; }  #正常,不截?cái)?
location /t4 { proxy_pass http://servers/; }  #正常,截?cái)?
location /t5/ { proxy_pass http://servers/test/; }  #正常,截?cái)?
location /t6/ { proxy_pass http://servers/test; }  #缺"/",截?cái)?
location /t7 { proxy_pass http://servers/test/; }  #含"http://",截?cái)?
location /t8 { proxy_pass http://servers/test; }  #正常,截?cái)?

測(cè)試腳本

for i in $(seq 8)
do
  url=http://tapi.xxxx.com/t$i/doc/index.html
  echo "-----------$url-----------"
  curl url
done

測(cè)試結(jié)果

----------http://tapi.xxxx.com/t1/doc/index.html------------
/t1/doc/index.html

----------http://tapi.xxxx.com/t2/doc/index.html------------
/doc/index.html

----------http://tapi.xxxx.com/t3/doc/index.html------------
/t3/doc/index.html

----------http://tapi.xxxx.com/t4/doc/index.html------------
/doc/index.html

----------http://tapi.xxxx.com/t5/doc/index.html------------
/test/doc/index.html

----------http://tapi.xxxx.com/t6/doc/index.html------------
/testdoc/index.html

----------http://tapi.xxxx.com/t7/doc/index.html------------
/test//doc/index.html

----------http://tapi.xxxx.com/t8/doc/index.html------------
/test/doc/index.html

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Nginx訪問(wèn)php文件直接下載的解決方法

    Nginx訪問(wèn)php文件直接下載的解決方法

    本文主要給大家介紹了如何解決Nginx訪問(wèn)php文件直接下載,這種情況通常是因?yàn)閚ginx沒(méi)有將PHP文件交給PHP解釋器處理,文中通過(guò)代碼示例給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2023-12-12
  • 詳細(xì)nginx多域名配置的方法

    詳細(xì)nginx多域名配置的方法

    Nginx綁定多個(gè)域名,可通過(guò)把多個(gè)域名規(guī)則寫(xiě)一個(gè)配置文件里實(shí)現(xiàn),也可通過(guò)分別建立多個(gè)域名配置文件實(shí)現(xiàn),為了管理方便,建議每個(gè)域名建一個(gè)文件,有些同類(lèi)域名則可寫(xiě)在一個(gè)總的配置文件里。下面這篇文章就來(lái)詳細(xì)看看nginx多域名配置的方法,有需要的朋友們可以參考。
    2016-12-12
  • Nginx部署vue項(xiàng)目和配置代理的問(wèn)題解析

    Nginx部署vue項(xiàng)目和配置代理的問(wèn)題解析

    這篇文章主要介紹了Nginx部署vue項(xiàng)目和配置代理,需本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,要的朋友可以參考下
    2021-08-08
  • nginx中配置使用proxy?protocol協(xié)議的全過(guò)程

    nginx中配置使用proxy?protocol協(xié)議的全過(guò)程

    proxy protocol是一個(gè)Internet協(xié)議,通過(guò)為tcp添加一個(gè)很小的頭信息,來(lái)方便的傳遞客戶(hù)端信息,在網(wǎng)絡(luò)情況復(fù)雜又需要獲取用戶(hù)真實(shí)IP時(shí)非常有用,這篇文章主要給大家介紹了關(guān)于nginx中配置使用proxy?protocol協(xié)議的相關(guān)資料,需要的朋友可以參考下
    2022-04-04
  • nginx結(jié)合openssl實(shí)現(xiàn)https的方法

    nginx結(jié)合openssl實(shí)現(xiàn)https的方法

    這篇文章主要介紹了基于nginx結(jié)合openssl實(shí)現(xiàn)https的方法,準(zhǔn)備工作大家需要安裝nginx服務(wù),具體操作過(guò)程跟隨小編一起看看吧
    2021-07-07
  • Mac環(huán)境Nginx配置和訪問(wèn)本地靜態(tài)資源的實(shí)現(xiàn)

    Mac環(huán)境Nginx配置和訪問(wèn)本地靜態(tài)資源的實(shí)現(xiàn)

    這篇文章主要介紹了Mac環(huán)境Nginx配置和訪問(wèn)本地靜態(tài)資源的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-09-09
  • 解決Nginx無(wú)法啟動(dòng) -10013: An attempt was made to access a socket in a way forbidden by its access permission的問(wèn)題

    解決Nginx無(wú)法啟動(dòng) -10013: An attempt was 

    這篇文章主要給大家介紹了解決用nginx -t 發(fā)成Nginx無(wú)法啟動(dòng)報(bào)錯(cuò)10013: An attempt was made to access a socket in a way forbidden by its access permissions的問(wèn)題,需要的朋友可以參考下
    2023-11-11
  • nginx中keepalive配置詳解

    nginx中keepalive配置詳解

    keepalive是長(zhǎng)連接的意思,本文主要介紹了nginx中keepalive配置詳解,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-08-08
  • 詳解Nginx 被動(dòng)檢查服務(wù)器的存活狀態(tài)

    詳解Nginx 被動(dòng)檢查服務(wù)器的存活狀態(tài)

    Nginx 可以持續(xù)測(cè)試您的上游服務(wù)器,避免出現(xiàn)故障的服務(wù)器,并將恢復(fù)的服務(wù)器優(yōu)雅地添加到負(fù)載均衡組中。這篇文章主要介紹了Nginx 被動(dòng)檢查服務(wù)器的存活狀態(tài),需要的朋友可以參考下
    2021-10-10
  • Nginx http運(yùn)行狀況健康檢查配置過(guò)程解析

    Nginx http運(yùn)行狀況健康檢查配置過(guò)程解析

    這篇文章主要介紹了Nginx http運(yùn)行狀況健康檢查配置過(guò)程解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-08-08

最新評(píng)論