Deploy multiple Rails apps on different Sub URIs, nginx

I recently had a requirement where I had to run two different Rails app’s on the same domain with different sub URI’s. The following was what I wanted to achieve:

www.example.com - Load Rails App1
www.example.com/app2 - Load Rails App2

This is very easy to achieve provided you are using Passenger Phusion + nginx. I made the following changes to the server block in nginx.conf

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 new addition passenger_base_uri directive. Now, we need to carry out the final step – symlink app2’s public folder to /var/www/app1/public/app2.

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

Once the symlink is created, restart nginx and you are ready to serve different Rails apps on the same domain.

References:

Leave a Reply

Your email address will not be published. Required fields are marked *