逃婚妈咪很惹火,像我这样一个女子,南方周末特稿
说明:
location 中的 root 和 alias
location 中的 proxy_pass 的 uri
如果 proxy_pass 的 url 不带 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/lctest4 location /lctest { root /data/web/; } location /lctest2/ { root /data/web/; } location /lctest3 { root /data/web; } location /lctest4/ { root /data/web; }
curl 测试结果如下
备注: 浏览器输入的时候最后面不添加 / , 会自动补上,但是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 测试结果如下
curl 'http://tapi.kaishustory.com/lctest5/' curl 'http://tapi.kaishustory.com/lctest6/' curl 'http://tapi.kaishustory.com/lctest7/' 结果都是 /data/web/的输出 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; } #正常,不截断 location /t2/ { proxy_pass http://servers/; } #正常,截断 location /t3 { proxy_pass http://servers; } #正常,不截断 location /t4 { proxy_pass http://servers/; } #正常,截断 location /t5/ { proxy_pass http://servers/test/; } #正常,截断 location /t6/ { proxy_pass http://servers/test; } #缺"/",截断 location /t7 { proxy_pass http://servers/test/; } #含"//",截断 location /t8 { proxy_pass http://servers/test; } #正常,截断
测试脚本
for i in $(seq 8) do url=http://tapi.xxxx.com/t$i/doc/ echo "-----------$url-----------" curl url done
测试结果
----------http://tapi.xxxx.com/t1/doc/------------ /t1/doc/ ----------http://tapi.xxxx.com/t2/doc/------------ /doc/ ----------http://tapi.xxxx.com/t3/doc/------------ /t3/doc/ ----------http://tapi.xxxx.com/t4/doc/------------ /doc/ ----------http://tapi.xxxx.com/t5/doc/------------ /test/doc/ ----------http://tapi.xxxx.com/t6/doc/------------ /testdoc/ ----------http://tapi.xxxx.com/t7/doc/------------ /test//doc/ ----------http://tapi.xxxx.com/t8/doc/------------ /test/doc/
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Nginx服务500:Internal Server Error原因之一
nginx禁止直接通过ip进行访问并跳转到自定义500页面的操作
网友评论