Forum: NGINX 2-phase proxying

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
412dd488538ddb80d5a48f4be68baf35?d=identicon&s=25 Mohammad Kolahdouzan (Guest)
on 2009-01-26 19:33
(Received via mailing list)
Hi,

I need to configure/modify nginx to use it in a 2-phase proxy kind of
configuration in which:
  - use the hash value of one of the arguments in the original uri to
find the index of the first backend server (defined in an upstream) that
needs to be called,
  - generate a separate request from the original request and send it to
the server specified in the previous stage,
  - parse the output of the first call and generate a second request and
send it to the second backend server (possibly defined through another
upstream),
  - return the reply from the second server back to the user

I am guessing that given the complexity, I would probably need to modify
nginx, or possibly write a new module. I am wondering if anyone has any
suggestions, maybe it is possible to do it with just modifying the
configuration(??), maybe there is something similar that is already
built in which I can use to modify, if not, what nginx module (proxy,
addition_filter, ...?) I need to modify or use to write my own module.

Thanks,
-M
Ab2425ae0425be8faaf052cce737b243?d=identicon&s=25 Michał Jaszczyk (Guest)
on 2009-01-26 22:05
(Received via mailing list)
On Mon, Jan 26, 2009 at 7:19 PM, Mohammad Kolahdouzan
<mohammad_ysm@yahoo.com> wrote:
> Hi,
>
> I need to configure/modify nginx to use it in a 2-phase proxy kind of
> configuration in which:
>   - use the hash value of one of the arguments in the original uri to find
> the index of the first backend server (defined in an upstream) that needs to
> be called,
>   - generate a separate request from the original request and send it to the
> server specified in the previous stage,

>   - parse the output of the first call and generate a second request and
> send it to the second backend server (possibly defined through another
> upstream),

Maybe it will be enough to use the X-Accel-Redirect feature?

Mike
412dd488538ddb80d5a48f4be68baf35?d=identicon&s=25 Mohammad Kolahdouzan (Guest)
on 2009-01-28 20:37
(Received via mailing list)
Is it possible to have a configuration similar to the following:

        location /x {
            proxy_pass http://www.yahoo.com;
        }

        location /y {
            add_before_body /x;
            add_after_body  http://www.google.com;
        }

which would supposedly add the content of the www.yahoo.com and
www.google.com before and after the content of the page at
/y/index.html? The addition filter module states that the texts after
add_before_body and add_after_body are URI, but the above config doesn't
seem to be doing it!

Thanks,
-M
Abbd9d5312c5d54114a96a35dc94fdb1?d=identicon&s=25 Valery Kholodkov (Guest)
on 2009-01-28 21:03
(Received via mailing list)
Probably this should work:

location /y {
     add_before_body @x;
     add_after_body @x;
}

location @x {
     proxy_pass http://www.yahoo.com;
}
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-01-28 21:15
(Received via mailing list)
On Wed, Jan 28, 2009 at 08:55:53PM +0100, Valery Kholodkov wrote:

> Probably this should work:
>
> location /y {
>     add_before_body @x;
>     add_after_body @x;
> }

No, add_before_body does not support named locations.
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-01-28 21:16
(Received via mailing list)
On Wed, Jan 28, 2009 at 11:21:35AM -0800, Mohammad Kolahdouzan wrote:

>
> which would supposedly add the content of the www.yahoo.com and www.google.com before 
and after the content of the page at /y/index.html? The addition filter module states that 
the texts after add_before_body and add_after_body are URI, but the above config doesn't 
seem to be doing it!

This should work, but it's better to use 0.7.32 for this:

         location = /x {
             proxy_pass http://www.yahoo.com/;
         }

         location = /g{
             proxy_pass  http://www.google.com/;
         }

         location /y {
             add_before_body /x;
             add_after_body  /q;
         }
This topic is locked and can not be replied to.