2

I recently decided to try out Rails. When working with PHP, I simply had all of my PHP projects in the same directory. For example, I may have http://ubuntu/app1, http://ubuntu/app2, etc.

I created a subdomain for Rails (http://ruby.ubuntu), installed Rails and Passenger and everything is working. However, I may be wrong, but it looks like I can only have one Rails app per subdomain?

My VirtualHost is as follows:

<VirtualHost *:80>
    ServerName ruby.ubuntu
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/ruby/blog/public

    <Directory /var/www/ruby/blog/public>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
        RailsEnv development
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

All of my PHP and misc. files are stored in /var/www/main. I want to be able to store all of my Rails apps in /var/www/ruby. I tried changing DocumentRoot to /var/www/ruby, but I don't think it's as simple as that. When I browse to a Rails app's Welcome Aboard page and click on "About my application's environment," I get a 404 page, but when the DocumentRoot is set to the public directory, I get the expected result.

I don't want to have to create a new subdomain every time I create a new project. Is there any way I can make it so I can store all of my apps in /var/www/ruby, and browsing to http://ruby.ubuntu will let me access all of my Rails apps there? That way if I want to create a new app, all I have to do is rails new app, no Apache .htaccess or VirtualHost configuration required.

1

3 Answers 3

5

you can serve as many rails applications as you wish.

If using apache httpd and passenger, here are the steps:

Just symlink public folder of each of your rails application into apache's DocumentRoot as a subfolder. Then add a RailsBaseURI directive in your apache config that tells passenger that the given folder is a rails application.

Lets say you have two rails apps rapp1 and rapp2. Lets say your apache DocumentRoot is /var/www/html

  ln -s rapp1 /var/www/html/rapp1
  ln -s rapp2 /var/www/html/rapp2

now open your apache virtual host configuration file and add the following two lines

  RailsBaseURI /rapp1
  RailsBaseURI /rapp2

restart your apache server and when you visit http://servername/rapp1, your rails application gets served

3
  • how to specify document root in conf
    – uzaif
    Dec 6, 2016 at 10:55
  • @uzaif did you ever figure out the document root or how to do this? I ran into this issue myself Mar 2, 2017 at 19:46
  • 1
    @SurgePedroza yes i resolved for running my multiple application on single instance
    – uzaif
    Mar 3, 2017 at 7:11
0

I could be mistaken but I believe what you're trying to achieve is called Sub-URI's.

Use the ruby.ubuntu subdomain and then each application runs under different /subdirectories.

Some further reading: http://collab.stat.ucla.edu/users/jose/weblog/9e335/

1
  • Forgive me if I'm wrong, but doesn't Sub-URI only assign a URI to a folder in the same way that Apache's mod_alias does? Using Sub-URI, I would have to create a new rule for every application. Jul 7, 2012 at 22:36
0

It looks like you're trying to use SubURIs. Passenger can support them, but you need to tweak your Virtual Host configuration a little.

The Passenger Docs for Apache explain how to do it, along with an example to give you a hand.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .