相关概念扫盲

  map指令

一  split_clients模块

说明: 这个模块属于'变量'系列

关注点1: 如何'产生'变量? -->'什么方式'

关注点2: 如何'使用'变量? -->'场景'

nginx sock5模块 nginx toa模块_应用场景

①  split_clients

1)基于'比例'来划分用户,不是通过'特征'来进行A/B测试的

2)思考:50%、50 % 能不能'实现轮询'的

3)贴近'灰度',变量以'ip'的形式,proxy_pass 中使用'$variant'变量

4)变量可以在'哪里'使用?

nginx sock5模块 nginx toa模块_变量_02

②  案例讲解

nginx sock5模块 nginx toa模块_变量_03

nginx sock5模块 nginx toa模块_nginx sock5模块_04

③  split_clients的应用场景

nginx sock5模块 nginx toa模块_nginx_05

nginx sock5模块 nginx toa模块_nginx_06

nginx sock5模块 nginx toa模块_nginx sock5模块_07

二  geo模块

nginx sock5模块 nginx toa模块_应用场景_08

理解:类似' map 模块'的'特殊'实现,专用于 'client ip' 场景

nginx sock5模块 nginx toa模块_变量_09

典型的应用场景

①  geo 指令

nginx sock5模块 nginx toa模块_优先级_10

②  geo 指令 {}中的6个可选参数

说明: 'proxy'和'proxy_recursive'效果类似'realip'模块的'real_ip_recursive'指令开关

细节点:include是相对于 '--conf-path'的路径

nginx sock5模块 nginx toa模块_nginx sock5模块_11

说明: 这里'proxy'的说法不准确,请看下面'proxy'的测试结果

proxy_recursive 

nginx sock5模块 nginx toa模块_优先级_12

③  案例1:使用默认的$remote_addr

realip模块修改$remote_addr

1)nginx如何'修改'$remote_addr

方式1: 在'post_read阶段'会'修改'remote_addr变量指向的内存值

备注: 对于'lvs(fullnat模式) + nginx',nginx是否安装'toa'模块也会影响'$remote_addr'

方式2: 在geo '新变量'使用之前,修改'$remote_addr',不一定非得在'post_read'阶段

优先级问题

 

nginx sock5模块 nginx toa模块_变量_13

说明:如果'多个'同时能匹配,则子网掩码'越大'(越精确),'优先级越高'

nginx sock5模块 nginx toa模块_变量_14

2)输出$美元符号 

说明: 其它方式'\'转义'$'不生效

nginx sock5模块 nginx toa模块_优先级_15

nginx sock5模块 nginx toa模块_nginx_16

3)使用default

 

nginx sock5模块 nginx toa模块_优先级_17

nginx sock5模块 nginx toa模块_nginx sock5模块_18

4)ranges场景 

nginx sock5模块 nginx toa模块_优先级_19

nginx sock5模块 nginx toa模块_nginx_20

nginx sock5模块 nginx toa模块_nginx_21

5)proxy场景

nginx sock5模块 nginx toa模块_优先级_22

+++++++++++++++++++++ "作用机制"  +++++++++++++++++++++

1)proxy:定义'可信'地址;

2)如果'请求源($remote_addr)'来自'可信地址(proxy 定义的)'范围

    [1]、如果有"X-Forwarded-For"请求头,则用'XFF'头的'最后一个ip地址'与geo中的'源值'进行匹配

    [2]、如果没有"X-Forwarded-For"请求头,则使用'$remote_addr'与geo指令中的'源值'进行匹配

3)相对于'普通'地址,可信地址是'顺序'检测的 -->也即'按照定义' 的顺序

注意: $remote_addr'不会'被修改 -->不管是'return'还是通过'nginx'的日志'可以看出'

nginx sock5模块 nginx toa模块_变量_23

nginx sock5模块 nginx toa模块_优先级_24

nginx sock5模块 nginx toa模块_nginx sock5模块_25

6)include

注意: include的'相对路径'和'语法格式'

nginx sock5模块 nginx toa模块_nginx sock5模块_26

7)delete

nginx sock5模块 nginx toa模块_nginx sock5模块_27

8)复杂场景

nginx sock5模块 nginx toa模块_nginx sock5模块_28

nginx sock5模块 nginx toa模块_nginx_29

④  自定义ip变量

nginx sock5模块 nginx toa模块_nginx_30

细节点: 此时跟'$remote_addr'没有'半毛钱'关系

nginx sock5模块 nginx toa模块_nginx_31

⑤  其它补充

nginx sock5模块 nginx toa模块_优先级_32

三  ngx_http_geo_module

说明: '了解'即可,后续有需要再'细看'

①  第一部分

nginx sock5模块 nginx toa模块_优先级_33

 ② geoip_country

nginx sock5模块 nginx toa模块_nginx sock5模块_34

③  geoip_city

nginx sock5模块 nginx toa模块_应用场景_35

④  其它

     geoip_org      geoip_proxy      geoip_proxy_recursive