说明:
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
curl 测试结果如下
备注: 浏览器输入的时候最后面不添加 / , 会自动补上,但是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 world4location alias
curl 测试结果如下
location proxy_pass
测试脚本
for i in $(seq 8)do url=http://tapi.xxxx.com/t$i/doc/index.html echo "-----------$url-----------" curl urldone测试结果
----------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以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。