Sunday, June 21, 2009

Configuring Apache 2 to front a Seaside application running on Pharo

My normal development machine is a MacBook Pro running OSX 10.5, and in order to have Apache serve my JS/CSS/Images I use the configuration that Ramon posted in his blog. This worked without problems on my laptop running OSX 10.5.

To-day, I began deploying my Seaside app on Ubunto, and ran into some problems with my current configuration. Apple's default configuration of Apache is not the same as a stock installation, which should not have surprised me.

I have Apache 2 installed on my Ubunto VMWare image, and had to do the following to get Apache to serve my JS/CSS/Images from port 80 and to re-direct to port 8080 for all my Seaside generated HTML.

Apache2 have a very nice configuration system for hosting multiple sites on the same server. In the /etc/apache2 directory you will find a directory called sites-available. In this directory I created this file (based on Ramon's rewrite rules for Seaside) :-

<virtualhost *:80>
ServerName juliet
DocumentRoot /home/jt/Dev/repos/git/juliet-site
<Directory /home/jt/Dev/repos/git/juliet-site/>
Options Indexes FollowSymLinks
Order allow,deny Allow from all
</Directory>

RewriteEngine On
ProxyRequests Off
ProxyPreserveHost On
UseCanonicalName Off
ErrorLog /home/jt/Dev/repos/git/juliet-site/juliet-error.log LogLevel debug

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ http://juliet:8080/$1 [P,L]
RewriteRule ^/seaside/(.*)$ http://juliet:8080/$1 [P,L]
</virtualhost>

This file configures a virtual host that serves all static documents from the configured directory, and for any files it cannot find, it rewrite the URL to be served by WACommanche running in my Smalltalk image.

Now from the command line I run $sudo a2ensite [name of my virtual host file]. This create a symlink from the sites-available file to the directory site-enabled. Apache will now read this file on startup.

Now Apache needs to be configured to Proxy my incoming requests, and although mod-proxy was installed as part of my default installation, I need to add the following to the /etc/apache2/mods-available/proxy.conf :-

<IfModule mod_proxy.c>
ProxyRequests On
<Proxy http://juliet:8080>
Order deny,allow Deny from all Allow from all
</Proxy> P
ProxyVia On
</IfModule>

Finally, I need to enable the proxy_http module to provide a protocol for the proxy module.

Running $sudo a2enmod proxy_http achieves this.

As I am still testing the app, I modified the hosts file to map juliet to 127.0.0.1.

Now when I point the browser at http://juliet/Juliet-BackOffice, Apache serves all my CSS/JS/images via port 80, and for any files not found, it re-directs to port 8080, where my Smalltalk image serves the required HTML.

There may be a simpler way to do this, but for now, I have my app running correctly with Apache as the front end.