So I've got two apps I want to run on a server. One app I would like to be the "default" app--that is, all URLs should be sent this app by default, except for a certain path, lets call it /foo
:
http://mydomain.com/ -> app1
http://mydomain.com/apples -> app1
http://mydomain.com/foo -> app2
My two rack apps are installed like so:
/var
/www
/apps
/app1
app.rb
config.ru
/public
/app2
app.rb
config.ru
/public
app1 -> apps/app1/public
app2 -> apps/app2/public
(app1
and app2
are symlinks to their respective apps' public directories). This is the Passenger setup for sub URIs described here: http://www.modrails.com/documentation/Users%20guide%20Nginx.html#deploying_rack_to_sub_uri
With the following config I've got /foo
going to app2:
server {
listen 80;
server_name mydomain.com;
root /var/www;
passenger_enabled on;
passenger_base_uri /app1;
passenger_base_uri /app2;
location /foo {
rewrite ^.*$ /app2 last;
}
}
Now, how do I get app1 to pick up everything else? I've tried the following (placed after the location /foo
directive), but I get a 500 with an infinite internal redirect in error.log
:
location / {
rewrite ^(.*)$ /app1$1 last;
}
I hoped that the last
directive would prevent that infinite redirect, but I guess not. /foo
gets the same error.
Any ideas? Thanks!
-
You should probably use subdomains if the apps are not closely related.
server { listen 80; server_name app1.mydomain.com; root /var/www/apps/app1; passenger_enabled on; passenger_base_uri /app1; }
If subdomains aren't an option then perhaps the alias directive will be of use.
From Martin F -
How did you manage to work it out with nginX. I've tried that, than I've tried with passenger. No luck on both sides.
: What I ended up doing was putting the two apps on two different servers. One of them had Apache out front (you could also use nginx) acting as a reverse proxy -- I added a list of proxy rules that either forwarded the request to localhost, or the second server. Not exactly what I wanted to do, but it ended up working great and in the long run is probably more scalable this way. Even better would be to put something like Pound in the front -- should be even more performant than starting up an entire Apache just as a proxy.From Kresimir Bojcic -
Hi I had a similar problem. The way I got around it was to insert the following in the server section of the nginx.conf file (although a bit of a hack, it does work):
error_page 403 /app1/homepage;
hope this helps
From jamesc -
I managed to get the following to work. For your example what you want for directory and symlink structure is this.
/var /www /apps /app1 app.rb config.ru /public /foo -> /var/www/apps/app2/public /app2 app.rb config.ru /public
Your nginx server block would then look like so:
server { listen 80; server_name mydomain.com; root /var/www/apps/app1/public; passenger_enabled on; passenger_base_uri /foo; }
Cheers, Mike D.
From Michael Deering
0 comments:
Post a Comment