介绍
这篇文章给大家介绍nginx位置中uri的截取,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
<强>说明:强>
中位置的根和别名
- <李>
根指令只是将搜索的根设置为根设定的目录,即不会截断uri,而是使用原始uri跳转该目录下查找文件
李> <李>若被指令则会截断匹配的uri,然后使用别名设定的路径加上剩余的uri作为子路径进行查找
中位置的proxy_pass的uri
如果proxy_pass的url不带uri
- <李>
如果尾部是“/?则会截断匹配的uri
李> <李>如果尾部不是“/?则不会截断匹配的uri
李>如果proxy_pass的url带uri,则会截断匹配的uri
<强>示例强>
<强>中位置的根强>
root@pts/1,美元,ls -ld /数据/web/lct * | awk & # 39; {print $ NF} & # 39;/数据/web/lct/数据/web/lctest2/数据/web/lctest3/数据/web/lctest4 位置/lctest { root 才能;/数据/web/; } 位置/lctest2, { root 才能;/数据/web/; } 位置/lctest3 { root 才能;/数据/网络; } 位置/lctest4, { root 才能;/数据/网络; }
<>强旋度测试结果如下强>
备注:浏览器输入的时候最后面不添加/,会自动补上,但是旋度不行
root@pts/1,美元curl http://tapi.xxxx.com/lctest/hello 世界 root@pts/1,美元curl http://tapi.xxxx.com/lctest2/hello 世界 2 root@pts/1,美元curl http://tapi.xxxx.com/lctest3/3. hello 世界 root@pts/1,美元curl http://tapi.xxxx.com/lctest4/hello 世界 4
<>强位置别名强>
的位置/lctest5 { alias 才能;/数据/web/; } 位置/lctest6, { alias 才能;/数据/web/; } 位置/lctest7 { alias 才能;/数据/网络; } # #,403/数据/web 禁止 位置/lctest8, { alias 才能;/数据/网络; }
<>强旋度测试结果如下强>
curl & # 39; http://tapi.kaishustory.com/lctest5/& # 39; curl & # 39; http://tapi.kaishustory.com/lctest6/& # 39; curl & # 39; http://tapi.kaishustory.com/lctest7/& # 39; 结果都是,/数据/web/index . html的输出 root@pts/1, $, curl & # 39; http://tapi.kaishustory.com/lctest8/& # 39; & lt; html> & lt; head> & lt; title> 403年,Forbidden & lt;/head> & lt; body 背景=皐hite"祝辞 & lt; center> & lt; h2> 403年,Forbidden & lt;/center> & lt; hr> & lt; center> nginx & lt;/body> & lt;/html>
<强>位置proxy_pass 强>
# - - - - - - - - - - proxy_pass配置- - - - - - - - - - - - - - - - - - - - - - - - 位置/t1/, {, proxy_pass http://servers,,},, #正常,不截断 位置/t2, {, proxy_pass http://servers/,,},, #正常,截断 位置/t3 {, proxy_pass http://servers,,},, #正常,不截断 位置/t4 {, proxy_pass http://servers/,,},, #正常,截断 位置/t5/, {, proxy_pass http://servers/test/,,},, #正常,截断 位置/t6, {, proxy_pass http://servers/test,,},, #缺“/敖囟? 位置/t7 {, proxy_pass http://servers/test/,,},, #含“//?截断 位置/t8 {, proxy_pass http://servers/test,,},, #正常,截断
<强>测试脚本强>
for 小姐:拷贝(seq 8)美元 做 url=http://tapi.xxxx.com/t才能$ i/doc/index . html echo 才能“$ url - - - - - - - - - - - - - - - - - - - - - - -产生绯闻; curl 才能;url 以前做><>强测试结果强>
- - - - - - - - - - - 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------------/测试/doc/index . html - - - - - - - - - - - http://tapi.xxxx.com/t6/doc/index.html------------/testdoc/index . html - - - - - - - - - - - http://tapi.xxxx.com/t7/doc/index.html------------/测试//doc/index . html - - - - - - - - - - - http://tapi.xxxx.com/t8/doc/index.html------------/测试/doc/索引。htmlnginx位置中uri的截取