# Trouble with somewhat complex proxy config

**URL:** <https://www.ruby-forum.com/t/trouble-with-somewhat-complex-proxy-config/214889>\
**Category:** NGINX\
**Created:** [December 15, 2011, 2:42am UTC](https://www.ruby-forum.com/t/trouble-with-somewhat-complex-proxy-config/214889 "2011-12-15T02:42:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [December 15, 2011, 2:42am UTC](https://www.ruby-forum.com/t/trouble-with-somewhat-complex-proxy-config/214889/1 "2011-12-15T02:42:56Z")

</div>

Hi,

So basically here is what I’m trying to accomplish:

1. I have several different rails apps running inside passenger  
standalone instances. I’d use the module, but I need to have separate  
ruby versions / parameters for each, so they’re happily on standalone  
instances.

2. The standalone instances run fine and I can connect to them.

3. Based on the presence of an argument “needle” in the GET params, I  
want to proxy pass to different locations. If the $needle is present, I  
want to proxy to $[needle.somehost.com](http://needle.somehost.com). Otherwise I want to proxy to  
localhost:3000. I know this sounds a little crazy, and I’d rather not  
get into “why,” suffice it to say it’s a pretty unique setup.

Here is my config, though it isn’t quite working out. I get internal  
errors from nginx after a long timeout.

server {  
listen host.ip.address:443 ssl;  
server\_name [host.server.com](http://host.server.com);  
root /var/www;

ssl\_certificate /my.crt;  
ssl\_certificate\_key /my.key;

error\_page 500 502 503 504 /50x.html;  
location = /50x.html {  
root html;  
}

location / {  
resolver dns.ip.address;  
if ($args ~\* needle=([a-z0-9-]+)&? ) {  
set $needle $1;  
proxy\_pass https://$needle.somehost.com;  
break;  
}  
proxy\_pass [http://127.0.0.1:3000](http://127.0.0.1:3000);  
proxy\_set\_header Host $host;  
}  
}

Any assistance would be greatly appreciated.

–  
Daniel J.  
Inigral, Inc. | The Social Web For Education

---

<div class="post-metadata">

**Author:** ![winsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a698b9/32.png) [@winsmith](https://www.ruby-forum.com/u/winsmith)\
**Post date:** [December 15, 2011, 3:20am UTC](https://www.ruby-forum.com/t/trouble-with-somewhat-complex-proxy-config/214889/2 "2011-12-15T03:20:32Z")

</div>

On Thu, Dec 15, 2011 at 3:42 AM, Daniel J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Here is my config, though it isn’t quite working out. I get internal errors from  
> nginx after a long timeout.

Check your error.log, I’m sure there is an explanation.

> }  
> Try this with map instead:  
> …

map $arg\_needle $needle\_host {  
default ‘127.0.0.1:3000’;  
~^ $arg\_needle.somehost.com;  
}

server {  
location / {  
proxy\_pass http://$needle\_host;  
}  
}

---

<div class="post-metadata">

**Author:** ![winsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a698b9/32.png) [@winsmith](https://www.ruby-forum.com/u/winsmith)\
**Post date:** [December 15, 2011, 1:58pm UTC](https://www.ruby-forum.com/t/trouble-with-somewhat-complex-proxy-config/214889/3 "2011-12-15T13:58:24Z")

</div>

Hello!

On Wed, Dec 14, 2011 at 05:42:35PM -0800, Daniel J. wrote:

> server {  
> }  
> }  
> }
> 
> Any assistance would be greatly appreciated.

What’s in error log?

Maxim D.

---

<div class="post-metadata">

**Author:** ![winsmith](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a698b9/32.png) [@winsmith](https://www.ruby-forum.com/u/winsmith)\
**Post date:** [December 15, 2011, 3:29am UTC](https://www.ruby-forum.com/t/trouble-with-somewhat-complex-proxy-config/214889/4 "2011-12-15T03:29:09Z")

</div>

> map $arg\_needle $needle\_host {  
> default ‘127.0.0.1:3000’;  
> ~^ $arg\_needle.somehost.com;  
> }

Or a bit more efficient, without regexes:

map $arg\_needle $needle\_host {  
default $arg\_needle.somehost.com  
‘’ ‘127.0.0.1:3000’;  
}
