服务器
这篇文章给大家介绍nginx location中uri的截取,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
说明:
location 中的 root 和 alias
root 指令只是将搜索的根设置为 root 设定的目录,即不会截断 uri,而是使用原始 uri 跳转该目录下查找文件
aias 指令则会截断匹配的 uri,然后使用 alias 设定的路径加上剩余的 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/lctest4location/lctest{root/data/web/;}location/lctest2/{root/data/web/;}location/lctest3{root/data/web;}location/lctest4/{root/data/web;}
curl 测试结果如下
备注: 浏览器输入的时候最后面不添加 / , 会自动补上,但是curl 不行
root@pts/1$curlhttp://tapi.xxxx.com/lctest/helloworldroot@pts/1$curlhttp://tapi.xxxx.com/lctest2/helloworld2root@pts/1$curlhttp://tapi.xxxx.com/lctest3/3helloworldroot@pts/1$curlhttp://tapi.xxxx.com/lctest4/helloworld4
location alias
location/lctest5{alias/data/web/;}location/lctest6/{alias/data/web/;}location/lctest7{alias/data/web;}##403/data/webforbiddenlocation/lctest8/{alias/data/web;}
curl 测试结果如下
curl\’http://tapi.kaishustory.com/lctest5/\’curl\’http://tapi.kaishustory.com/lctest6/\’curl\’http://tapi.kaishustory.com/lctest7/\’结果都是/data/web/index.html的输出root@pts/1$curl\’http://tapi.kaishustory.com/lctest8/\'<html><head><title>403forbidden</title></head><bodybgcolor=\”white\”><center><h2>403forbidden</h2></center><hr><center>nginx</center></body></html>
location proxy_pass
#——–proxy_pass配置———————location/t1/{proxy_passhttp://servers;}#正常,不截断location/t2/{proxy_passhttp://servers/;}#正常,截断location/t3{proxy_passhttp://servers;}#正常,不截断location/t4{proxy_passhttp://servers/;}#正常,截断location/t5/{proxy_passhttp://servers/test/;}#正常,截断location/t6/{proxy_passhttp://servers/test;}#缺\”/\”,截断location/t7{proxy_passhttp://servers/test/;}#含\”//\”,截断location/t8{proxy_passhttp://servers/test;}#正常,截断
测试脚本
foriin$(seq8)dourl=http://tapi.xxxx.com/t$i/doc/index.htmlecho\”———–$url———–\”curlurldone
测试结果
———-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
关于nginx location中uri的截取就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
华为云弹性云服务器怎么升级配置LVS的四种模式和十种调度算法简介什么样的文案能激发客户购买欲阿里云和实体服务器哪个好用云服务器租用价格需要多少对百度有啊进军B2C的一点想法云服务器里可以放多少网站我想请问一下的域名不能备案吗