Nginx复制到mirror1的请求保留30%,复制到mirror2的请求保留40%,并记录mirror1和mirror2的response。
http {
# ...
server {
listen 80;
location / {
# 启用Lua代理
proxy_pass http://your_upstream;
proxy_set_header Host $host;
# 设置Lua代理参数
proxy_set_body $body_bytes_sent;
# 调用Lua脚本处理请求
content_by_lua_block {
local res = ngx.location.capture("/lua_proxy", {
method = ngx.var.request_method,
body = ngx.var.request_body,
})
-- 检查子请求的状态
if res.status == 200 then
ngx.status = res.status
ngx.say(res.body) -- 转发子请求的response
else
ngx.status = res.status
ngx.say("Error: " .. res.body)
end
}
}
location /lua_proxy1 {
internal;
proxy_pass http://your_upstream;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_body $request_body;
}
location /lua_proxy2 {
internal;
proxy_pass http://your_upstream;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_body $request_body;
}
}
}