September 13, 2006

Setting up proxy.pac with apache2

Introduction

This guide will briefly take you through the process of setting up a automatic proxy configuration file hosted on debian server running apache2 so your client machines can configure themselves to use whatever proxies you might have.

Writing a proxy.pac

proxy.pac is the de-facto name for the proxy configuration file and is essentially a file containing the function definition for FindProxyForURL. This function is called by the browser when it attempts to connect to a URL in order to determine how it should do so.

At the very least the file must contain:
function FindProxyForURL(url, host)
{
return "PROXY <your.proxy.server>:<port>";
}
Naturally you can do a lot more with this function, but that is beyond the scope of this article.

Setting up apache2

Now that you have a proxy.pac, you need to put it somewhere where clients can access it, and it must have a mime-type of application/x-ns-proxy-autoconfig otherwise it won't work. One way to do this is to create a .htaccess file in the same directory and place in it the following line:
AddType application/x-ns-proxy-autoconfig .pac
In order for apache2 to read .htaccess you need the AllowOverride option in the proper <directory></directory> directive to be All or sufficiently permissive, for example:
<Directory />
Options +FollowSymLinks
AllowOverride All
</Directory>
And we are done

Once all that is setup, just point your clients to http://where.proxy.pac.is.hosted/proxy.pac and tell them to use that for automatic proxy configuration. And viola!

Well it worked for me anyways...

Cheers,
Steve