Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx - Redirect requests to all backends

I have 5 backend servers. I want nginx to forward the POST request for /myapp/refresh to all 5 backend servers. For any other request, it can do load balancing. Is this possible ? Can you please give a sample configuration ?

like image 399
RDR Avatar asked Feb 13 '17 15:02

RDR


2 Answers

I'm not aware about ready to use solution to do what you want.

It is definetely possible to implement such behavior in C or Lua.

You may develop nginx C module, but it not trivial task with serious learning curve.

You may use https://github.com/openresty/lua-nginx-module and use something like https://github.com/openresty/lua-nginx-module#ngxlocationcapture_multi.

But in both cases you should implement some kind of logic when and which response you will send back.

Question to think about - do you need to respond with 200 OK if one of the backend will time out or responds with error?

like image 116
Alexander Altshuler Avatar answered Oct 21 '22 06:10

Alexander Altshuler


You can try use the The ngx_http_mirror_module module (1.13.4), this implements mirroring of an original request by creating background mirror subrequests. Responses to mirror subrequests are ignored. https://nginx.org/en/docs/http/ngx_http_mirror_module.html

like image 22
armsultan Avatar answered Oct 21 '22 07:10

armsultan