Trouble with somewhat complex proxy config

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. 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;
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;
proxy_set_header Host $host;
}
}

Any assistance would be greatly appreciated.


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

On Thu, Dec 15, 2011 at 3:42 AM, Daniel J. [email protected] 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;
}
}

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.

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’;
}

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs