Frontier and Apache, 1 Public Port

One of the lingering issues with serving using Frontier on OSX is integration with static content. I have a legacy site that is static html pages (served by webstar) administered by a set of fcgis (currently run by appleevents from WebStar) that I want to migrate to OSX. The appleevent interface appears to be gone from OSX, and I have apache instead of WebStar. But since Frontier has the CGI responder allowing it to respond to fcgi requests through its own webserver, the transition is surprisingly easy.

The basic idea is that I am going to use Apache to proxy requests to Frontier, running on the same machine but a different port number. The example I’m presenting here is for fcgi extensions, but by tweaking the expressions, it should be possible to forward any combination of requests to Frontier, while serving the rest from Apache.

For this example, I have Frontier listening to port 8000. The cgi responder should be enabled, and you should be able to access your fcgi script directly at http://yourmachine.com:8000/script.fcgi.

Apple helpfully ships Apache with the proper modules installed (mod_rewrite, mod_proxy), but you will need to enable mod_proxy. Mod_rewrite is already enabled in the default configuration.

Edit the file /etc/httpd/httpd.conf, (as root). Yon need to uncomment the following lines:

#LoadModule proxy_module       libexec/httpd/libproxy.so
#AddModule mod_proxy.c

so that they look like this

LoadModule proxy_module       libexec/httpd/libproxy.so
AddModule mod_proxy.c

For each site you wish to proxy, you will need to add a configuration file (as root) in the /etc/httpd/users directory (e.g. fcgi.conf) with the following contents:

    DocumentRoot /Volumes/Frontier/websites/staticSite
    ServerName virtual.example.com
    RewriteEngine on
    RewriteRule ^/(.*)\.fcgi(.*)$$1.fcgi$2 [P]

This is a standard VirtualHost directive the partial equivalent of config.mainresponder.domains, making the contents only apply to the host named virtual.example.com. ( where *.example.com points to the same ip address. (similar to how editthispage.com works)). The document root should be set to the #folder in the #ftpSite table. If you want to do this for all of the sites and pages served by apache, you can omit all but the rewrite lines.

The RewriteEngine line turns on mod rewrite so that it intreprets the next line.

The RewriteRule line means: match anything that starts with a slash (^/), contains “.fcgi” and might have something after it ((.*)$)., rewrite the url so that it points to our local port 8000, including all the stuff before and after the .fcgi, and proxy the request ([P]).

Any time you change an Apache config file, you will need to stop and restart web sharing in the System Preferences -> sharing control panel. (or sudo /usr/sbin/apachectl graceful)

When presented with the request, Apache will make a request to Frontier, which will serve the content to Apache, which will then return it to the client. Ths client will never see Frontier’s url.

The beauty of this approach is that any url that you can characterize bu a regular expression can be forwarded to Frontier for its response. For further information, see the Apache Manual for mod_rewrite or the Rewriting Guide. This should work for running Frontier behind Apache on any platform (OSX, Unix, Windows).

No comments

No comments yet. Be the first.

Leave a reply

You must be logged in to post a comment.