0

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!

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
  • I've pretty much given up on this and gone to good old fashioned thin clusters which nginx then acts as a proxy for. Dumb Passenger. –  Feb 23 '10 at 23:37

5 Answers5

1

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.

0

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.

Martin Fjordvald
  • 7,589
  • 1
  • 28
  • 35
0

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. –  Jul 14 '10 at 04:52
0

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

0

Instead changing in nginx, you can do it in MMVC(Multi MVC) in Sinatra itself using rack

run Rack::Cascade.new [ IndexApp, BlogApp, TestApp, ThisApp, ThatApp]

Using this you can run multiple apps in using nginx passenger. As passenger needs public folder I created a dummy public folder and under public I created folders for managing individual assets, like public/blog/ public/index public/test etc.

mgorven
  • 30,036
  • 7
  • 76
  • 121
vamshi
  • 1