佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > nginx location中uri的截取的實(shí)現(xiàn)方法

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

熱門標(biāo)簽:使用U盤裝系統(tǒng) 網(wǎng)站建設(shè) 阿里云 美圖手機(jī) 智能手機(jī) 百度競價(jià)點(diǎn)擊價(jià)格的計(jì)算公式 檢查注冊表項(xiàng) 硅谷的囚徒呼叫中心

說明:

location 中的 root 和 alias

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

location 中的 proxy_pass 的 uri

如果 proxy_pass 的 url 不帶 uri

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

如果proxy_pass的url帶uri,則會截?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 測試結(jié)果如下

備注: 瀏覽器輸入的時(shí)候最后面不添加 / , 會自動補(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 測試結(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)?

測試腳本

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

標(biāo)簽:通遼 懷化 黃山 賀州 煙臺 湘潭 湖北 山南

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《nginx location中uri的截取的實(shí)現(xiàn)方法》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    玛纳斯县| 阿尔山市| 娄烦县| 广宗县| 务川| 平遥县| 措勤县| 桐柏县| 桦甸市| 伊宁县| 台前县| 乌什县| 鱼台县| 磐石市| 察雅县| 洪洞县| 惠来县| 保德县| 攀枝花市| 汪清县| 济宁市| 清新县| 乡宁县| 鄂尔多斯市| 惠东县| 桂阳县| 永仁县| 广东省| 谷城县| 会理县| 洛川县| 汕尾市| 鸡东县| 昭苏县| 文昌市| 阿城市| 双桥区| 孟村| 开封市| 富顺县| 辛集市|