nginx
nginx各种配置
location路径配置原则和优先级
nginx一般用做代理服务器,并且通过location 来配置路径,以下通过几个例子来进行说明:
location /{ }这种写法的匹配优先级最高,用于匹配 /a 的路径,如路径是 /a/b则不通过该匹配;1
2
3
4
5
6
7
这种写法是匹配默认地址,即 ip/ (如localhost/)以及在conf的location路由规则中没有定义过的路径(如 ip/QwQ,也会匹配上)。
- ```
location =/a {
}这种写法的匹配优先级次高,优先级小于 =/a 的优先级,即路径为 ip/a 则优先被 =/a 匹配, ip/a/b 被^~/a匹配;1
2
3location ^~/a{
}
反向代理
1 | |
反向代理总结
1 | |
负载均衡
1、在server配置上面,添加
1 | |
2、编写location代理
1 | |
3、others
此外,还可以配置负载均衡的权重:
如:
1 | |
nginx
http://yoursite.com/2020/01/09/nginx各种配置/