nginx 流量复制
- - 开源软件 - ITeye博客# 后端的Web服务器可以通过X-Forwarded-For获取用户真实IP. #设置 $url ==原url. #新接口地址改变的,需要转换url. #新接口地址改变的,需要转换url. 已有 0 人发表留言,猛击->> 这里<<-参与讨论. —软件人才免语言低担保 赴美带薪读研.
#原接口
upstream api{
server 127.0.0.1:8080;
}
#新接口
upstream newapi{
server 127.0.0.1:8081;
}
#原接口后端
location /api{
proxy_pass http://api;
# 后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
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_request_body on;
}
#复制流量打入新接口
location /newapi{
#设置 $url ==原url
set $url $request_uri;
#新接口地址改变的,需要转换url
if ( $request_uri = /api/interfaceName1 ){
set $url "/api/newInterface1";
}
#新接口地址改变的,需要转换url
if ( $request_uri = /api/interfaceName2 ){
set $url "/api/newInteface2";
}
proxy_pass http://newapi$url;
proxy_set_header X-Original-URI $request_uri;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}