Running external FastCGI XMLRPC server behind Apache 2.2

Another frustration and several lost hours worth few lines in blog. My goal was to run our FastCGI application locally behind a Web server. Our production setup has Lighttpd, but installing it on my just reinstalled MacBook looked a bit too much. Well, not now having lost so many hours trying to figure out few steps, but nevertheless…

Another frustration and several lost hours worth few lines in blog. My goal was to run our FastCGI XMLRPC server locally behind a Web server. Our production setup uses Lighttpd, but installing it on my just reinstalled MacBook looked a bit too much. Well, not anymore, having lost so many hours trying to figure out few steps, but nevertheless…

What we have

  • A standalone FastCGI application that serves XMLRPC and is already started by hand or another way (active fcgi back-end mode) running on e.g. post 8081
  • A Web server acting as a front-end running on e.g. post 8080

All we need is to forward the XMLRPC calls from clients received by the front-end to the back-end.

Lighttpd

server.modules += ( "mod_fastcgi" )
$SERVER["socket"] == ":8080" {
fastcgi.server = (
"/RPC2" =>(( "host" => "127.0.0.1",
"port" => 8081,
"check-local" => "disable",
"docroot" => ""))) }

(I have removed a lot of ‘beautification’ for brevity).

Apache
Well, this caused me hours of trial and error, but finally it is shockingly simple


Listen 8080
FastCgiExternalServer /var/www/blah -host 127.0.0.1:8081
<VirtualHost *:8080>
RewriteEngine On
RewriteRule ^/RPC2$ /blah [QSA,L]
</VirtualHost>

So where is the catch? Well, there seem to be several. And I am not saying that they are completely not described, it is just that it was not obvious for some reason. Anyway…

  1. The path to the external FastCGI server. There is no ‘blah’ in my ‘/var/www/’ ! Moreover, my application has a totally different name, but… that does not matter. What does matter is that the path mentioned before the ‘blah’ MUST exist and Apache MUST have access to it. As correctly described in some very good documentation this is just a ‘handle’, but Apache still checks whether it has proper access rights to this path. So DO NOT put ANY path there as some may suggest, but make sure it is a valid one. The easiest ‘hack’ is to use the overall DocumentRoot.
  2. Depending on your implementation of the FastCGI XML-RPC server you may want to rewrite ^/$ or ^/RPC2$, but note that here you have to use the same name ‘/blah’ provided for the external FastCGI server. This is the only place the name is needed to have the mapping (pretty confusing actually and looks more like a hack to me).

After all the mod_proxy_fastcgi seemed like a better alternative, but that one is only for Apache 2.3, while I am happily stuck with 2.2 on MacOSX Snow Leopard for the moment.

Happy configuring!