Archive

Archive for February, 2013

Apache Virtual Host and Rails

February 15, 2013 Leave a comment

I started working on a new rails project and wanted to use specific domain names and route traffic through port 80.  There are several ways to setup Apache as front to your Rails application but I only wanted stock Apache and a standalone rails instance.   I didn’t want to hassle with anything else.

1) Start your Rails server as you normally would.  Let’s assume it’s running at http://localhost:3000

2) Create an Apache Virtual Host that proxies requests to  http://localhost:3000

<VirtualHost *:80>
ServerName test.application.vhost
ProxyPreserveHost On
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
</VirtualHost>

3) Edit your /etc/hosts file to route test.application.vhost to 127.0.0.1

Notes for Mac OS Lion
Virtual Hosts are configured in /etc/apache2/extra/httpd-vhosts.conf
If necessary, modify “/etc/apache2/httpd.conf” and uncomment the line “Include /private/etc/apache2/extra/httpd-vhosts.conf”
sudo apachectl configtest
sudo apachectl restart

Advertisements
Categories: Uncategorized