Proxy Page

Squid cache logo

Squid’s default error page are pretty boring, and I was wondering if I could replace them with nicer ones. The pages are build using templates stored in the /opt/share/squid/errors/English/ directory, and they are simple text files with some printf style substitutions. There are two problems with this, first, squid needs to be restarted each time the files are changed, which is annoying, second one can only serve one text file, so no external style sheet or image files. Of course it is possible to embed everything, into the web page, by inlining the CSS and by using the data: protocol for images, but this is cumbersome.

A better solution is to have a page with a minimal amount of layout and do everything in an external CSS file. My NAS is running a web-server, so style sheets and images can be served from there, but how do I reference them. I could hardcode the ip address of the NAS in the template, but this feels brittle, if the server’s address changes, I’ll need to rewrite all templates. I first thought of using the mulicast DNS, in my case tekai.local, this worked very well with Mac OS X and my iPhone, but not so well with my Android tablet and my Chromebook. Those two devices seem to have limited support for RFC 6762. The squid templates offers a %I code that gets resolved to the address of the proxy. Alas, this is the externally visible IP address, and the web-server’s port is not visible on that side.

In the end I used a small hack: insert the server’s multicast DNS name into the /etc/hosts file. Mac OS X and iOS will see the .local name and resolve it by themselves, others will send the request for the resource to the proxy, which will resolve it using its static configuration and will call the web-server collocated with the proxy. The header of my template files look like this now:

<html>
<head>
<title>Error: requested URL could not be retrieved</title>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="http://tekai.local/squid/style.css" />
<base href="http://tekai.local/squid/" />
</head>

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: