Send all requests to two separate upstream servers?

I have a need to adjust a nginx install doing reverse proxy to a single
server now to adjust it to send all requests it receives to two
different
upstream servers.

I was thinking I could do it with the configuration below, but I wasn’t
sure if that would work and I’d have to use re-write rules instead.

upstream original_upstream {
server
}
upstream new_upstream {
server
}

server {
location / {
proxy_pass http://original_upstream;
}
location / {
proxy_pass http://new_upstream;
}

Any suggestions?

Eric Feldhusen

Option A and that’s what I figured as well.

Eric Feldusen

On Tue, Jun 17, 2014 at 10:08 AM, Richard K. [email protected]

On 17/06/14 15:13, Eric Feldhusen wrote:

I have a need to adjust a nginx install doing reverse proxy to a
single server now to adjust it to send all requests it receives to two
different upstream servers.
do you mean
a) send each request to both?
b) send each request to one or the other (like load balancing)

a) is not possible, simply because of the basics of proxying and http
(there would be 2 http responses mixed into 1 connection)
b) can be done with 1 / location but adding another address to the
upstream block:

|upstream backend {
server
||| server |
}|

|server {
location / {
proxy_passhttp://backend http://original_upstream;
}
}|

Option A and that’s what I figured as well.

Depends on what you actually want to achieve by doing those 2 requests –
eg
is it to prewarm 2 backend cache servers or something?

But one way to do this would be for example to use nginx Lua module
GitHub - openresty/lua-nginx-module: Embed the Power of Lua into NGINX HTTP servers /
ngx.location.capture_multi , content_by_lua etc and then from one
response
discard the body ( ngx.req.discard_body ) or just print the first.

… theoretically maybe also the Echo module
GitHub - openresty/echo-nginx-module: An Nginx module for bringing the power of "echo", "sleep", "time" and more to Nginx's config file but I’m
not
exactly sure how the “combined” response would look like and if the
duplicate body could be avoided just by sending HEAD request to the
second
backend.

You can test it yourself or try to ask agentzh.

rr

On 17/06/14 16:12, Eric Feldhusen wrote:

Option A and that’s what I figured as well.

If you don’t care about sending the upstream response back to the
client, or want to pick one of the two responses to send back
then you can use the nginx lua module to perform some obscure
functionality… it’s quite a bit more advanced but something you might
want to look into

however the response would be fully buffered before it could be sent to
client, so may be quite a delay and a memory hog if it’s something large

Hi

On Tue, Jun 17, 2014 at 3:09 PM, Eric Feldhusen wrote:

I’m looking for a way to mirror my production site traffic to a development
environment, so that I have nearly identical traffic going to both to work
through some optimization issues that are hard to do without the load, which
is just incoming data.

Sounds like a perfect use case for the tcpcopy tool:

https://github.com/wangbin579/tcpcopy

Best regards,
-agentzh

That’s almost perfect, except I don’t have enough access to the
development
environment to get it installed.

Eric

On Tue, Jun 17, 2014 at 5:27 PM, Yichun Z. (agentzh)
[email protected]

You are wanting to multi-purpose a production env for dev without proper
parameters in ur setup.

Set a system to use as ur test client requesting http, setup an if
statement and match proper fields and proxy_pass proxyA or proxy_pass
proxyB

Id setup the more specific match on top

Only an idea, im sure there are half a dozen ways of doing this… Just
not without proper plan


Payam C.
Network Engineer / Security Specialist

I’m looking for a way to mirror my production site traffic to a
development
environment, so that I have nearly identical traffic going to both to
work
through some optimization issues that are hard to do without the load,
which is just incoming data.

Eric