Apache and RoR
Posted by Quinn at July 9th, 2007 12:47am under web 0 Comments Permalink
This is about how to set up web server to run RoR with Apache in front.
I am hosting several domains with Apache and its VirtualHost directories. I was wondering if I could run Rails with the same server and the same port. Yes, I knew the anwer was mod_proxy but never tried before. Well, that had to change. Here is what I came up this time. It was pretty easy and nice.
There is no mod_proxy package/port for FreeBSD. I had to recompile Apache2.0 with this configuration.
echo "WITH_PROXY_MODULES=yes" >> /etc/make.conf
Then, I did.
portupgrade -f apache2
Easy way, huh? But if you don't have portupgrade, you may have to do..
# cd /usr/ports/www/apache20 # make deinstall # make install clean
Then, I added these lines in the apache config file.
# vi /usr/local/etc/apache2/httpd.conf
LoadModule proxy_module libexec/apache2/mod_proxy.so LoadModule proxy_ftp_module libexec/apache2/mod_proxy_ftp.so LoadModule proxy_http_module libexec/apache2/mod_proxy_http.so LoadModule proxy_connect_module libexec/apache2/mod_proxy_connect.so
Make a new Rails app.
$ mkdir -p /path/to/application $ rails /path/to/application $ cd /path/to/application $ mongrel_rails start -d
Lastly, mod_rewrite does the rest with [p] flag.
$ cd /path/to/application $ vi .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) http://localhost:3000/$1 [P]
Now, I can access to the Rails application without specifying the port number but a url to the directory just like the others. In this way, I don't have to reconfigure the router to open the ports every time I start new RoR. Cool. Isn't it?











