Displaying articles with tag

Successful Settings for Apache forwarding to Mongrel

Posted by hardwarehank, Thu Jun 15 14:14:37 UTC 2006

So, after a day of working on it, I finally fixed the problems I was having.

I wanted to have Apache forward all traffic hitting a path to a mongrel server running in a rails application. So, I did as bish0p suggested, and set up the rails app to accept this behavior. First, I put this at the bottom of my environment.rb:


ActionController::AbstractRequest.relative_url_root = "/MyRailsApp"

This make it so all the urls in the Rails app are prepended with /MyRailsApp. Without this, you’ll get renders that don’t have stylsheets, javascripts, or anything else that resides in the public directory of rails.

Second, I made a ProxyPass entry in the Apache configuration:


Redirect /MyRailsApp http://www.example.com/MyRailsApp/
ProxyPass /MyRailsApp/ http://localhost:6402/MyRailsApp/
ProxyPassReverse /MyRailsApp/ http://localhost:6402/MyRailsApp/

This allows all traffic that goes to /MyRailsApp on the server to be redirected to my mongrel server, which is running on port 6402 (This port does not have to be unfirewalled since all the requests are done locally by Apache).

Next, I have to further fix the problem of mongrel not being able to find things in public by making a symlink in public to itself. Make sure not to just do a link to ../public. Here’s an example:


cd public
mkdir MyRailsApp # This has to be whatever you used in your Apache configuration.
cd MyRailsApp
ln -s ../* . # Link to everything above.
rm MyRailsApp # Get rid of the recursive link.

Now, just configure your db, application, etc. and start the mongrel server from the root of the application.


mongrel_rails start -p 6402 -e production -d

And voila! You have a working ProxyPass connection from Apache to Mongrel.

Update:

Thanks to this article, I now have mod_deflate running! It was very easy to install:


apxs -c -i mod_deflate.c # As Root

This will install it to your apache installation’s modules directory. Now, just add some lines in your config:


Redirect /MyRailsApp http://www.example.com/MyRailsApp/
ProxyPass /MyRailsApp/ http://localhost:6402/MyRailsApp/
<Location /MyRailsApp>
  ProxyPassReverse /MyRailsApp
  SetOutputFilter INFLATE;proxy-html;DEFLATE
  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript
</Location>

Congratulations, you’re now deflating your HTML/XML/CSS/JS/PlainText files! This works on all modern browsers (yes, even Lynx), and greatly reduces the size of the files sent. Here’s a summary:

Before:
14.4K: 172.65 seconds
28.8K: 86.32 seconds
33.6K: 73.99 seconds
56K: 44.40 seconds
ISDN 128K: 13.60 seconds
T1 1.44Mbps: 1.18 seconds

After:
14.4K: 52.27 seconds
28.8K: 26.13 seconds
33.6K: 22.40 seconds
56K: 13.44 seconds
ISDN 128K: 4.12 seconds
T1 1.44Mbps: 0.36 seconds

Roughly 3 times as fast!!

Also, it may be possible to leave off a lot of the junk here. I might have to streamline the configuration some in the following days. If I’m right, you won’t even need the ActionController line anymore.

Tags:

Collaboa Trunk Install

Posted by hardwarehank, Wed Jun 14 03:54:58 UTC 2006

Well, I guess I might as well finish the job as much as I can before bed. I’m going to install Collaboa. Here’s the beginning:

Get rails and mongrel, along with all the deps:


sudo gem install rails mongrel redcloth syntax sqlite3-ruby xhtmldiff

Now, get ruby-mysql, which requires some junk on FC5:


sudo yum install mysql mysql-devel
sudo gem install mysql -- --with-mysql-config

Now, get the trunk:


svn co http://svn.collaboa.org/svn/collaboa/trunk/ collaboa --username=anon --password=anon

I’m going to use SQLLite for this project. I have to make the database:


touch db/pdn.db

Here’s my database.yml:


production:
  adapter: sqlite3
  dbfile: db/pdn.db

Now, I have to tell it where my repositories are (config/repository.yml):


production:
  repos_path: /path/to/repos/hank

Now that the database and repository files are setup, I have to import the schema and default settings:


RAILS_ENV="production" rake db_schema_import
RAILS_ENV="production" ruby db/default_content.rb

Now I finally sync the repository with the database:


./script/repository_syncer

Time to start mongrel!


mongrel_rails start -p 3010

Now, I redirect the apache server to mongrel when /browse is accessed (I’m running mongrel on port 3010)(bottom of conf.d/svn.conf):


Redirect /browse  http://example.com/browse
ProxyPass /browse/ http://localhost:3010/browse/
ProxyPassReverse /browse/ http://localhost:3010/browse/

NOTEs:

  • Make sure that BOTH YOUR PROXYPASS LINES HAVE A FINAL / AT THE END OF EACH ARGUMENT. This will solve the redirection limit errors.
  • Make a symbolic link in public to itself, and call it whatever you named the proxypass (in this example, browse). This will stop the no-images/stylesheets madness.

Tags:

Mongrel/WEBrick Forwarding in Apache

Posted by hardwarehank, Wed Jun 14 02:55:48 UTC 2006

This will let you redirect an apache request to a local mongrel or webrick server. Very handy, yet maybe some logging of the used ports would be good at some point.


<VirtualHost collaboa.example.com:80>
  Servername collaboa.example.com
  CustomLog /www/collaboa/logs/access.log combined
  ErrorLog  /www/collaboa/logs/error.log
        ProxyPass / http://127.0.0.1:3005/
        ProxyPassReverse / http://127.0.0.1:3005/
</VirtualHost>

Tags: