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.

I was able to successfully configure nginx and passenger phusion. I now have the following configuration

server {listen 80  server_name **sub1.example.com** root /home/user/app1/public }    
server {listen 80  server_name **sub2.example.com** root /home/user/app2/public }

Now, I want to change it to the following configuration

server {listen 80  server_name **dev.example.com/example1** root /home/user/app1/public }
server {listen 80  server_name **dev.example.com/example2** root /home/user/app2/public }

I tried using the location directive, but wasn't successful. I'm not even sure if this is possible. Any help would be greatly appreciated. Thanks.

The following are my nginx.conf settings

server {
   listen 80;
   server_name dev.example.com;

location = /app1/ {
   root /home/rails/app1/public/; 

   passenger_enabled on;
   rails_env development;
}
location /app2/ {
   root /home/rails/app2/public/; 
   passenger_enabled on;
   rails_env development;
}
}
share|improve this question

2 Answers 2

Previous Answer:

 server_name dev.example.com/example1 

is wrong. I am understanding you wanted dev.example.com to go to dev.example.com/example1. For such case, you need to do URL rewrite like below

location = / { rewrite ^ http://dev.example.com/example1 ; }

Answer after the comment:

From your comment i understood you wanted to serve multiple rails app from within same URI/domain.

server {
    listen 80;
    server_name dev.example.com;
    root /home/user/app1/public;
    passenger_enabled on;
    passenger_base_uri /app2;
    passenger_base_uri /app3;
    ....truncated...
    rails_spawn_method smart;
    rails_env production;
}
share|improve this answer
    
Kaji, what I want to do is instead of creating a sub-domain for every app I have, I would like to do something like this Have one super sub domain - dev.example.com and then redirect to the app's public folders when requests come. For example, dev.example.com/app1 - points to app1/public dev.example.com/app2 - points to app2/public dev.example.com/app3 - points to app3/public I have updated my question with my configuration. It might help you understand the problem better. –  Naz Mir Feb 6 '12 at 9:58
    
I have updated the answer ...hope that solves for ya' –  kaji Feb 6 '12 at 10:43
    
Kaji, thanks for the inputs. I stumbled upon the problem again yesterday and this time I solved it. –  Naz Mir Sep 18 '13 at 8:24
up vote 0 down vote accepted

This is possible by making use of Passenger Phusion's passenger_base_uri directive. Let us assume my domain is www.example.com

Now I want to run multiple rails applications for the following URI's

www.example.com - Load Rails App1

www.example.com/app2 - Load Rails App2

This is how my Server block in nginx.conf would look like:

server {
      listen 80;
      server_name  www.example.com;
      root /var/www/app1/public;   
      passenger_enabled on;
      passenger_base_uri /app2;
}

Look at how the root is pointing to app1's public folder. And look at the passenger_base_uri directive.

Now we need to carry out the final step - symlink app2's public folder to /var/www/app1/public/app2, this is done by running the following command:

ln -s /var/www/app2/public /var/www/app1/public/app2

Once you create this link, restart nginx and you are ready to serve different Rails apps on the same domain.

References: Deploying Passenger Phusion to a sub URI

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.