Welcome! Log In Create A New Profile

Advanced

RE: Proxy Retry Logic

Sirsiwal, Umesh
December 22, 2010 08:52PM
Thanks Marcus.
I really like echo module. My module's subrequest handling is modeled after the excellent echo module. We have significant custom logic to deal with our specific needs.

I did not realize try_files can use with proxy locations. I did see the internal redirect in the configuration example used proxy. But, I did not realize that I could use it in other places.

I tried using
location /sub1 {
proxy_pass http://www.1google.com;
}
resolver 216.195.0.131;
location /sub2 {
proxy_pass http://www.google.com;
}
location @s {
proxy_pass http://www.yahoo.com;
}


location / {
try_files /sub1/$uri /sub2/$uri @s;
}

I always get www.yahoo.com. Looking at the logs:
2010/12/22 20:44:55 [debug] 1607#0: *1 try to use file: "/sub1//" "/Users/umesh/nginx/install/html/sub1//"
2010/12/22 20:44:55 [debug] 1607#0: *1 http script copy: "/sub2/"
2010/12/22 20:44:55 [debug] 1607#0: *1 http script var: "/"
2010/12/22 20:44:55 [debug] 1607#0: *1 try to use file: "/sub2//" "/Users/umesh/nginx/install/html/sub2//"
This was followed by testing @s which served the content.

I tried replacing /sub1 and /sub2 with named location and I get:
2010/12/22 20:48:52 [debug] 1637#0: *3 try to use file: "@sub1" "/Users/umesh/nginx/install/html@sub1"
2010/12/22 20:48:52 [debug] 1637#0: *3 try to use file: "@sub2" "/Users/umesh/nginx/install/html@sub2"
This was followed by testing @s which served the content.

How can I configure try_files to use proxy_location?

-Umesh
________________________________________
From: Eugaia [ngx.eugaia@gmail.com]
Sent: Wednesday, December 22, 2010 8:19 PM
To: nginx-devel@nginx.org
Subject: Re: Proxy Retry Logic

Hi,

On 22/12/2010 21:26, Sirsiwal, Umesh wrote:
All,
I am trying to write a module which uses a number of subrequests to talk to backend servers. Combines the responses and sends them back to the client. The communication with the backend server is using HTTP and I am using proxy_pass for that.

The peculiarity in our setup is that on failure-retry I need to use a different URI than the original request. Current, proxy reinit request does not regenerate request hence cannot be used for the purpose. I tried using the error_page in the subrequest location to point to a different location. But, it seems that the error_page is not evaluated on subrequest. The only option I can think of is for my module to detect error and issue a new subrequest.

Is this the best solution for this problem? Will that affect subrequest response concatenation?
I think you can do this now using the echo module (http://wiki.nginx.org/HttpEchoModule), subrequests and try_files

e.g.

location /main {
echo_location /sub1; # could also be echo_location_async
echo_location /sub2; # (ditto)
}

location /sub1 {
try_files ...
}

location /sub 2 {
try_files ...
}

Where ... in try_files are the separate proxy locations.

I'm not certain (and I've not tested / looked at the code) what happens when a proxied request returns a non-200 response, but I am assuming that try_files tries the next location on the list. If it does (and it should if it doesn't), and you know the URL of the new testing location, then this method should work.

A word of caution about using both synchronous and asynchronous echo_ commands next to one another. There used to be (and I'm not sure if they've been fixed yet or not) issues with this. Use either sync or async combined and you should be fine (async is probably a better option, since it's likely to give a faster response to the client in this case).

Cheers,

Marcus.

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Proxy Retry Logic

Sirsiwal, Umesh 2513 December 22, 2010 02:28PM

Re: Proxy Retry Logic

Maxim Dounin 962 December 22, 2010 06:40PM

RE: Proxy Retry Logic

Sirsiwal, Umesh 1049 December 22, 2010 07:56PM

Re: Proxy Retry Logic

Eugaia 973 December 22, 2010 08:20PM

RE: Proxy Retry Logic

Sirsiwal, Umesh 1019 December 22, 2010 08:52PM

Re: Proxy Retry Logic

Eugaia 1076 December 22, 2010 09:10PM

RE: Proxy Retry Logic

Sirsiwal, Umesh 887 December 22, 2010 09:26PM

Re: Proxy Retry Logic

Eugaia 954 December 22, 2010 09:38PM

RE: Proxy Retry Logic

Sirsiwal, Umesh 965 December 22, 2010 09:52PM

Re: Proxy Retry Logic

Eugaia 1196 December 23, 2010 04:00AM

Re: Proxy Retry Logic

Eugaia 1029 December 23, 2010 04:36AM

RE: Proxy Retry Logic

Sirsiwal, Umesh 1213 December 23, 2010 08:12AM

Re: Proxy Retry Logic

Eugaia 913 December 22, 2010 09:22PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 106
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready