Apache Passenger displaying the Rails application contents

apache-2.2phusion-passengerrubyruby-on-rails

I have installed mod_rails (phusion passenger) for Apache on Ubuntu 11.10. Ruby and Rails are running fine, and so does mod_rails.

I have setup a site on dev.localhost, which is my ruby app. The app is called my_project which resides in var/www/my_project

My virtualhost for it successfully points to the 'public' directory of my ruby app and it seems to work. If I access dev.localhost – my ruby application works perfectly, there are no complaints. However, if I access localhost/my_project, my entire ruby application is displayed, the Gemfile, the controllers, all it's directories – everything. It displays the directory's content.

My virtual hosts file for my rails app:

<VirtualLHost *:80>
RailsEnv development
ServerName dev.localhost
DocumentRoot /var/www/my_project/public
</VirtualHost>

Why is this? I can't figure it out. I've tried .htaccess files, everything, but those obviously also reflect on dev.localhost.

How can I stop people from seeing the ruby application files on say localhost/my_project? It doesn't display it on dev.localhost, it displays the site 100%.

What am I missing here?

Best Answer

You've attached a Name-based VirtualHost (by using ServerName dev.localhost) to port 80 on all interfaces, but you haven't set a default VirtualHost so it's using the main DocumentRoot configuration (probably in /etc/apache2/conf/apache2.conf). Two options:

  • Replace *:80 with _default_:80 and remove the ServerName option, meaning this VirtualHost will handle all connections on port 80 regardless of the Host: header provided.
  • Add another sites-enabled file with a _default_:80 VirtualHost that points to a DocumentRoot containing a page informing users there is no site configured on this hostname. This approach is forward-looking if you plan to deploy multiple name-based VirtualHosts.