# Dynamic Proxy Passing

**URL:** <https://www.ruby-forum.com/t/dynamic-proxy-passing/185766>\
**Category:** NGINX\
**Created:** [March 25, 2010, 7:13pm UTC](https://www.ruby-forum.com/t/dynamic-proxy-passing/185766 "2010-03-25T19:13:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ensiferous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e274bd/32.png) [@Ensiferous](https://www.ruby-forum.com/u/Ensiferous)\
**Post date:** [March 25, 2010, 7:13pm UTC](https://www.ruby-forum.com/t/dynamic-proxy-passing/185766/1 "2010-03-25T19:13:14Z")

</div>

Hello,

I have a situation where a server needs to proxy to a variable backend  
depending on the URI.

I use x-accel-redirect to a URI like /files/serverX/fileY;

I then need my server to proxy\_pass to [serverX.domain.com/fileY](http://serverX.domain.com/fileY); and  
return this data to the user.

There will be multiple servers with this so something where I need to  
update the configuration when I add a new serverX would be somewhat  
undesirable.

Question is, what’s the best way to go about this?

Posted at Nginx Forum:

> **[Dynamic Proxy Passing](https://forum.nginx.org/read.php?2,67784,67784#msg-67784)**
>
> Hello, I have a situation where a server needs to proxy to a variable backend depending on the URI. I use x-accel-redirect to a URI like /files/serverX/fileY; I then need my server to proxy\_pass to serverX.domain.com/fileY; and return this data to...

---

<div class="post-metadata">

**Author:** ![Ensiferous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e274bd/32.png) [@Ensiferous](https://www.ruby-forum.com/u/Ensiferous)\
**Post date:** [March 26, 2010, 5:01pm UTC](https://www.ruby-forum.com/t/dynamic-proxy-passing/185766/2 "2010-03-26T17:01:53Z")

</div>

This is just conceptual but you could try (if the ‘serverX’ is like a  
prefix  
for a subdomain):

location ~ /files/(._)/(._) {  
proxy\_pass http://$1.domain.com/$2;  
}

This way you just need also to define a resolver (  
[Module ngx\_http\_core\_module](http://wiki.nginx.org/NginxHttpCoreModule#resolver) ) if your hosts are  
not  
defined in upstream{} block or IPs.

rr

* * *

From: “Ensiferous” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Sent: Thursday, March 25, 2010 8:12 PM  
To: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Dynamic Proxy Passing

---

<div class="post-metadata">

**Author:** ![Ensiferous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e274bd/32.png) [@Ensiferous](https://www.ruby-forum.com/u/Ensiferous)\
**Post date:** [March 27, 2010, 11:02am UTC](https://www.ruby-forum.com/t/dynamic-proxy-passing/185766/3 "2010-03-27T11:02:55Z")

</div>

Yes. this was the conclusion I came to as well after talking it over in  
the IRC channel. Using IPs is probably the ideal here.

Posted at Nginx Forum:

> **[Re: Dynamic Proxy Passing](https://forum.nginx.org/read.php?2,67784,68364#msg-68364)**
>
> Hello, I have a situation where a server needs to proxy to a variable backend depending on the URI. I use x-accel-redirect to a URI like /files/serverX/fileY; I then need my server to proxy\_pass to serverX.domain.com/fileY; and return this data to...
