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

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?

2 Answers 2


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.

It looks like there is a +Indexes set somewhere in your apache2 configuration. Adding this block to your VirtualHost block (or into your httpd.conf) should solve it.

<Directory "/var/www/my_project">
    Options -Indexes

This will override a +Indexes option that is set somewhere in your httpd configuration to serve all /var/www content as indexable.

Also, instead of a catchall virtualhost, consider <VirtualLHost dev.localhost:80>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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