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

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

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

說明:

location 中的 root 和 alias

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

location 中的 proxy_pass 的 uri

如果 proxy_pass 的 url 不帶 uri

  • 如果尾部是"/",則會截斷匹配的uri
  • 如果尾部不是"/",則不會截斷匹配的uri

如果proxy_pass的url帶uri,則會截斷匹配的uri

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 測試結(jié)果如下

備注: 瀏覽器輸入的時候最后面不添加 / , 會自動補上,但是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 測試結(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; }  #正常,不截斷
location /t2/ { proxy_pass http://servers/; }  #正常,截斷
location /t3 { proxy_pass http://servers; }  #正常,不截斷
location /t4 { proxy_pass http://servers/; }  #正常,截斷
location /t5/ { proxy_pass http://servers/test/; }  #正常,截斷
location /t6/ { proxy_pass http://servers/test; }  #缺"/",截斷
location /t7 { proxy_pass http://servers/test/; }  #含"http://",截斷
location /t8 { proxy_pass http://servers/test; }  #正常,截斷

測試腳本

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

測試結(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

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

相關(guān)文章

  • Nginx訪問php文件直接下載的解決方法

    Nginx訪問php文件直接下載的解決方法

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

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

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

    Nginx部署vue項目和配置代理的問題解析

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

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

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

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

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

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

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

    解決Nginx無法啟動 -10013: An attempt was 

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

    nginx中keepalive配置詳解

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

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

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

    Nginx http運行狀況健康檢查配置過程解析

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

最新評論