8 messages in ru.sysoev.nginxRe: Dynamic proxy_pass
FromSent OnAttachments
W. Andrew Loe IIIJul 29, 2008 6:34 pm 
张立冰Jul 29, 2008 6:57 pm 
mikeJul 29, 2008 7:43 pm 
W. Andrew Loe IIIJul 30, 2008 10:22 am 
W. Andrew Loe IIIJul 30, 2008 2:08 pm 
mikeJul 30, 2008 2:16 pm 
W. Andrew Loe IIIAug 1, 2008 1:46 pm 
mikeAug 1, 2008 5:14 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: Dynamic proxy_passActions...
From:张立冰 (zhan@public.gmane.org)
Date:Jul 29, 2008 6:57:57 pm
List:ru.sysoev.nginx

Here is some code maybe will help you...:)

if ($host ~* (.+)\.(.*)\.91\.com(.*)) { set $dir_a $1; set $dir_b $2;

rewrite ^(.*)$ /activity/$dir_b/$dir_a$1 last; }

location / { proxy_pass http://127.0.0.1:8080; }

On Wed, Jul 30, 2008 at 9:34 AM, W. Andrew Loe III
<andrew-4trK/3dDa@public.gmane.org>wrote:

I have a relatively complex setup but I believe nginx has the ability to do everything I am looking for. I want to proxy requests for files to different servers using x-accel-redirect.

A request cycle might look like this: client => interwebs => nginx1 => mongrel (which does some lifting and then replies back with x-accel-redirect and a url like /under_the_covers/10.10.1.2/file.jpg) => nginx1 (at this point the location directive catch the /under_the_covers and do what I want) => some-other-webserver (10.10.1.2) => nginx1 => interwebs => client.

In psuedo code I want something like:

location /under_the_covers/(.*) { internal; proxy_pass http://$1; }

I have tried a few methods but I cannot seem to get it correct.

location /under_the_covers/ { rewrite ^/under_the_covers/(.*)/(.*)$ $2; proxy_pass http://$1; }

I have no trouble if I manually set the host in the proxy pass. So the mongrel replies with x-accel-redirect = /under_the_covers/file.jpg and location looks like so:

location /under_the_covers/(.*) { proxy_pass http://10.10.1.2; }

http://article.gmane.org/gmane.comp.web.nginx.english/6206/match=proxy_pass

There is discussion there on using proxy_pass with variables but I cannot either construct the uri correctly or I can't get the hostname set from a regular expression.

Thank you for your time, -- Andrew