有没有办法配置Nginx同时向多个上游服务器广播传入请求?

swo*_*ger 6 nginx

以下片段将一次选择一个服务器.有没有办法立刻击中它们?

upstream backend {
    server 17.0.0.1:8000;
    server 17.0.0.1:8001;
    server 17.0.0.1:8002;
    server 17.0.0.1:8003;

}

server {
    location / {
        proxy_pass http://backend;
    }
}
Run Code Online (Sandbox Code Playgroud)

Pas*_*aux 5

这是使用ngx_http_mirror_module的解决方案(从 nginx 1.13.4 开始可用):

server {
    location / {
        proxy_pass http://17.0.0.1:8000;
        mirror /s1;
        mirror /s2;
        mirror /s3;       
    }
    location /s1 { internal; proxy_pass http://17.0.0.1:8001$request_uri; }
    location /s2 { internal; proxy_pass http://17.0.0.1:8002$request_uri; }
    location /s3 { internal; proxy_pass http://17.0.0.1:8003$request_uri; }
}
Run Code Online (Sandbox Code Playgroud)

nginx 将:

  • 向所有服务器发送相同的请求
  • 等待所有这些完成
  • 响应http://17.0.0.1:8000响应(并忽略其他响应)