濮阳杆衣贸易有限公司

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

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

熱門(mén)標(biāo)簽:廣州電銷(xiāo)機(jī)器人系統(tǒng)圖 智能電話機(jī)器人線路 長(zhǎng)沙開(kāi)福怎么申請(qǐng)400電話 高德地圖標(biāo)注無(wú)營(yíng)業(yè)執(zhí)照 百度地圖標(biāo)注要不要錢(qián) 江蘇電銷(xiāo)外呼防封系統(tǒng)是什么 賀州市地圖標(biāo)注app 金融行業(yè)外呼線路 東莞人工智能電銷(xiāo)機(jī)器人供應(yīng)商

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

標(biāo)簽:廊坊 滄州 松原 張家界 洛陽(yáng) 永州 北京 玉樹(shù)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《nginx location中uri的截取的實(shí)現(xiàn)方法》,本文關(guān)鍵詞  nginx,location,中,uri,的,截,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《nginx location中uri的截取的實(shí)現(xiàn)方法》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于nginx location中uri的截取的實(shí)現(xiàn)方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    遂平县| 正定县| 镇雄县| 房山区| 石景山区| 县级市| 黄平县| 南投县| 天等县| 阳江市| 福安市| 大悟县| 富裕县| 楚雄市| 长泰县| 双江| 乐陵市| 高邑县| 银川市| 汕头市| 鹤岗市| 商河县| 宁明县| 建昌县| 秦皇岛市| 临沧市| 阳春市| 沾益县| 房产| 阿瓦提县| 阳高县| 奇台县| 通州区| 岐山县| 大埔县| 广灵县| 浪卡子县| 昌江| 呼玛县| 龙州县| 始兴县|