nginx实战(三) ------ location和rewrite配置2
2019-04-02 15:37
295 查看
一. nginx执行流程
- 首先通过域名(IP) + 端口号定位到指定的虚拟机(服务器)
- 通过path匹配location , path = 匹配path(匹配中的) + 剩余path(未匹配中的) , 结合有/与无/讲解 , 代码如下 :
[code]#后台原始访问路径: http://127.0.0.1:8088/aaa/order/getOrder #无/ 访问路径: http://localhost:8088/aaa/order/getOrder location /aaa/order { #匹配路径/aaa/order 剩余路径/getOrder proxy_pass http://127.0.0.1:8088; #此处未关闭,传递整个路径/aaa/order/getOrder到目标 ip:port } #有/ 访问路径: http://localhost:8088/ss/aaa/order/getOrder location /ss { #匹配路径/ss 剩余路径/aaa/order/getOrder proxy_pass http://127.0.0.1:8088/; #此处关闭,只传递/aaa/order/getOrder到目标ip:port }
注 : proxy_pass的/关闭与不关闭 , 只是针对ip + port之后有没有/号 , 例如http://127.0.0.1:8088/ss这种 , 就已经算作关闭了
- 讲解同一静态文件两种方式访问 , 代码如下 :
[code]#访问路径: http://localhost:8088/static/a.html location /static { #匹配路径/static, 剩余路径/a.html root html/; #root声明,在html文件夹,查找/static/a.html文件 } #访问路径: http://localhost:8088/target/a.html location /target{ #匹配路径/target , 剩余路径/a.html alias html/static/; #alias声明,在html/static/文件夹,查找a.html文件 }
-
root的处理结果是 : root转发匹配path + 未匹配path , 建议使用绝对路径
-
alias的处理结果是 : alias只转发未匹配path , 目录别名 , 使用alias路径替换location路径 , alias后面必须用"/"结束 , 而root则可有可无
二. location执行优先级
=精准匹配 , 匹配就直接返回
无前缀和^~为普通匹配 , 收集所有匹配 , 去最长匹配执行(此时不反悔 , 还会执行下面的正则匹配)
~,~*为正则匹配 , 按顺序依次匹配 , 匹配中即返回(可能会覆盖普通匹配)
相关文章推荐
- nginx配置location总结及rewrite规则写法
- nginx配置location总结及rewrite规则写法
- nginx配置location总结及rewrite规则写法
- Nginx 配置 location 总结及 rewrite 规则写法
- nginx配置location总结及rewrite规则写法
- nginx配置location总结及rewrite规则写法
- nginx配置location总结及rewrite规则写法
- nginx配置location总结及rewrite规则写法
- 【转】nginx配置location总结及rewrite规则写法
- nginx配置location总结及rewrite规则写法
- nginx配置location总结及rewrite规则写法【转】
- Nginx教程(四) Location配置与ReWrite语法
- nginx配置location总结及rewrite规则写法
- Nginx配置location总结及rewrite规则写法
- nginx配置location总结及rewrite规则写法
- Nginx配置location总结及rewrite规则写法
- nginx配置location总结及rewrite规则写法
- nginx配置location总结及rewrite规则写法
- nginx配置location总结及rewrite规则写法
- nginx配置location总结及rewrite规则写法