Is there a way to configure Nginx to broadcast incoming requests to multiple upstream servers simultaneously?

Here is a solution using ngx_http_mirror_module (available since 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; }
}

nginx will:

  • send the same request to all servers
  • wait for all of them to finish
  • respond with the http://17.0.0.1:8000 response (and ignore the others)

Tags:

Nginx