1. 需要
将生产环境的流量拷贝到预上线环境或测试环境,这样做有很多益处,比方:
- 能够验证性能是否失常,以及服务的性能;
- 用真实有效的流量申请去验证,又不必造数据,不影响线上失常拜访;
- 这跟灰度公布还不太一样,镜像流量不会影响实在流量;
- 能够用来排查线上问题;
- 重构,如果服务做了重构,这也是一种测试形式;
- 为了实现流量拷贝,Nginx提供了ngx_http_mirror_module模块
2. 源码装置
yum装置没有蕴含咱们所需的ngx_http_mirror_module模块,因而,真正要应用的时候最好还是采纳自定义装置,即从源码构建
首先,下载源码 http://nginx.org/en/download....
接下来,编译装置,例如:
./configure --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --without-http_limit_req_module --without-http_mirror_module --with-pcre=../pcre-8.43 --with-zlib=../zlib-1.2.11 --add-module=/path/to/ngx_devel_kit --add-module=/path/to/lua-nginx-modulemake & make install
3. 配置
upstream api.abc.com { server 127.0.0.1:8080;}upstream tapi.abc.com { server 127.0.0.1:8081;}server { listen 80; # 源站点 location /api { proxy_pass http://api.cjs.com; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 流量复制 mirror /newapi; mirror /mirror2; mirror /mirror3; # 复制申请体 mirror_request_body on; } # 镜像站点 location /tapi { proxy_pass http://tapi.cjs.com$request_uri; proxy_pass_request_body on; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }}
4. 文档
- Nginx文档
http://nginx.org/en/docs/
http://nginx.org/en/docs/http...
http://nginx.org/en/docs/begi...
http://nginx.org/en/docs/http...
http://nginx.org/en/docs/conf...