Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
    
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. –  Anonymous Feb 23 '10 at 23:37
add comment

5 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
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. –  Anonymous Jul 14 '10 at 4:52
add comment

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.