人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動態(tài)

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

發(fā)布日期:2022-03-10 14:57 | 文章來源:腳本之家

說明:

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í)有所幫助,也希望大家多多支持本站。

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部