Home arrow Tricks, Tips, and Help arrow Code and Documentation for Programmers arrow Rails Mongrel and Apache all together now 2
Rails Mongrel and Apache all together now 2 Print E-mail
From my prior doc  Rails Mongerl and Apache All togerher now 1 I created a very basic rails application, mostly for the purpose of displaying text, and maybe some images afterwards. I am going to run mongrel which I installed with

gem install mongrel

to see whether what I wrote displays through mongrel. I run

script/console

Which runs mongrel on port 3000. So I navigate to

http://jibwa.com:3000/photo

and I get XML back

Now I know my Rails is working properly and is rendering form the db. Now I need to get apache
to serve up the mongrel application. There are two ways to do this. For development I let apache start mongrel each time a user access the page. I just manually add virtual host entries to the httpd.conf

>vim /etc/httpd/conf/httpd.conf

Now I haven't installed any special mods to apache, its pretty much the default configuration I got from rackspace. I have a namevirtualhost entry

NameVirtualHost 128.196.77.111:80

Then a list of vhosts. To get my rails app to run I need to make a new vhost that points at the public directory.

<VirtualHost rails.jibwa.com:80>
        ServerName rails.jibwa.com
        DocumentRoot /home/jbwhite/rubyprojects/photoalbum/public
        ErrorLog /var/log/httpd/jral
</VirtualHost>

Now I have all I need done to the httpd.conf file so I quit and save. Reload Apache with
> /etc/init.d/httpd reload

Now I navigate to
rails.jibwa.com/photo and I see my xml.

This works great for development. I set developers and myslef up in this way. Edits can be made to the dev installation and you never have to restart mongrel, it just reloads the whole rails app each time someone access the page.

The best way for production is to have rails running constantly in the background, and then use a proxypass to the port it is running under. This just requires that you run mongrel in deamon mode, and probably on a different port. Then setting the proxypass up in httpd.conf

When you install mongel it installs a nice little application which allows you to start mongrel in different modes. So I run

> mongrel_rails start -d -p 9876

Then I make sure I can navigate to the site on that port. I go to http://jibwa.com:9876 and I see my welcome to rails message and know that the daemon mode is running fine. If you want to stop it, just goto your rails application direcrtory and type

> mongrel_rails stop

So last we modify at the apache conf file and change the virtualhost from before to look like this.

<VirtualHost rails.jibwa.com:80>
        ServerName rails.jibwa.com
#       DocumentRoot /home/jbwhite/rubyprojects/photoalbum/public
        ErrorLog /var/log/httpd/jral
        ProxyPass / http://rails.jibwa.com:9876/
        ProxyPassReverse / http://rails.jibwa.com:9876
        ProxyPreserveHost on


</VirtualHost>

Now I navigate to rails.jibwa.com and it loads much quicker. I hope this helps, and if anyone knows any other tricks and tips for this I would gladly like to hear them.







 
Next >

Jibwa Work Samples

Under Construction

Jibwa.com is under construction. Watch out for broken links, missing pages, potholes and bulldozers. We apologize for the temporary inconvenience - Jibwa.com Staff

News and Updates

Doran Photographic Works

A local Tucson photographer was looking for the best way of displaying and selling his photography on the web. We ended up finding the best solution w...
Read More ...

Boyd Energy Site

A energy engineer wanted a place to share his knowledge of energy conservation and other building type technologies. Using Joomla 1.5 we have a site u...
Read More ...

Restart Cable Modem and Router

If you have a modem (Cable, DSL, T1, Other), and a router you are probably familiar with the power cycle! The power cycle is three simple steps and ...
Read More ...

Lecture Audio Clip Player

Mark Pirtle Website Russell Public was interested in having Mark's audio samples playable for visitors of the website. In order to do this we had to ...
Read More ...