国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > Nginx > 正文

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

2024-08-30 12:24:29
字體:
供稿:網(wǎng)友

說明:

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/lctest4location /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 worldroot@pts/1 $ curl http://tapi.xxxx.com/lctest2/hello world2root@pts/1 $ curl http://tapi.xxxx.com/lctest3/3hello worldroot@pts/1 $ curl http://tapi.xxxx.com/lctest4/hello world4

location alias

location /lctest5 {  alias /data/web/;}location /lctest6/ {  alias /data/web/;}location /lctest7 {  alias /data/web;}## 403 /data/web forbiddenlocation /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)鄉(xiāng)ocation /t2/ { proxy_pass http://servers/; }  #正常,截?cái)鄉(xiāng)ocation /t3 { proxy_pass http://servers; }  #正常,不截?cái)鄉(xiāng)ocation /t4 { proxy_pass http://servers/; }  #正常,截?cái)鄉(xiāng)ocation /t5/ { proxy_pass http://servers/test/; }  #正常,截?cái)鄉(xiāng)ocation /t6/ { proxy_pass http://servers/test; }  #缺"/",截?cái)鄉(xiāng)ocation /t7 { proxy_pass http://servers/test/; }  #含"http://",截?cái)鄉(xiāng)ocation /t8 { proxy_pass http://servers/test; }  #正常,截?cái)?/pre>

測(cè)試腳本

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

測(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            
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 衡阳县| 宁海县| 越西县| 湘潭县| 岳普湖县| 张家口市| 和林格尔县| 云安县| 嵊泗县| 蓬安县| 阿图什市| 定襄县| 广平县| 朝阳市| 扬州市| 景谷| 鄢陵县| 黄山市| 县级市| 高要市| 抚顺市| 都江堰市| 泸定县| 南通市| 牙克石市| 徐州市| 鲜城| 阳新县| 乐昌市| 垫江县| 鄂州市| 株洲市| 措勤县| 资阳市| 隆昌县| 阜宁县| 东丰县| 迭部县| 定结县| 汝州市| 宜章县|