Forum: NGINX Send all requests to two separate upstream servers?

F86200d51638fc64e412eaf91ab3b751?d=identicon&s=25 Eric Feldhusen (Guest)
on 2014-06-17 16:14
(Received via mailing list)
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   <ip address>
}
upstream  new_upstream  {
    server   <ip address>
}

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


Any suggestions?


Eric Feldhusen
Ebfa54c92a50798dfdbbdb4e28ed1f29?d=identicon&s=25 Richard Kearsley (Guest)
on 2014-06-17 17:09
(Received via mailing list)
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   <ip address>
|||     server   <ip address>|
}|

|server {
     location / {
         proxy_passhttp://backend  <http://original_upstream>;
     }
}|
F86200d51638fc64e412eaf91ab3b751?d=identicon&s=25 Eric Feldhusen (Guest)
on 2014-06-17 17:13
(Received via mailing list)
Option A and that's what I figured as well.

Eric Feldusen


On Tue, Jun 17, 2014 at 10:08 AM, Richard Kearsley <richard@kearsley.me>
Ebfa54c92a50798dfdbbdb4e28ed1f29?d=identicon&s=25 Richard Kearsley (Guest)
on 2014-06-17 17:25
(Received via mailing list)
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

http://wiki.nginx.org/HttpLuaModule
http://wiki.nginx.org/HttpLuaModule#ngx.location.c...

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
56080a668b706e94fb2bbe9ee727d006?d=identicon&s=25 Reinis Rozitis (Guest)
on 2014-06-17 17:36
(Received via mailing list)
> 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
https://github.com/openresty/lua-nginx-module#ngxl... /
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
https://github.com/openresty/echo-nginx-module#ech...  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
F86200d51638fc64e412eaf91ab3b751?d=identicon&s=25 Eric Feldhusen (Guest)
on 2014-06-18 00:09
(Received via mailing list)
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
37f3ea777f96500b332a1a89d6027897?d=identicon&s=25 Yichun Zhang (agentzh) (Guest)
on 2014-06-18 00:28
(Received via mailing list)
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
F86200d51638fc64e412eaf91ab3b751?d=identicon&s=25 Eric Feldhusen (Guest)
on 2014-06-18 05:22
(Received via mailing list)
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 Zhang (agentzh)
<agentzh@gmail.com>
D0a98f6304ff122ac9b487ff8275d8bb?d=identicon&s=25 Payam Chychi (Guest)
on 2014-06-18 05:31
(Received via mailing list)
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 Chychi
Network Engineer / Security Specialist
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.