Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my network, I've some Ubuntu machines which need to download files from Since it's quite a waste of time to download everything multiple times, I've setup a squid proxy for caching the data.

Another use for this proxy was rewriting requests for or * to because this mirror is faster than the US mirrors.

This has worked quite well, but after a recent install of my caching machine, the configuration was lost. I remember having a separate perl program for handling this rewrite.

How do I setup such a squid proxy which rewrites the host * to and cache the result of the latter?

share|improve this question
up vote 2 down vote accepted

To rewrite mirror requests from * to, you need to create the a rewrite helper and configure squid to use this helper for rewriting requests.

In the squid configuration (e.g. /etc/squid-deb-proxy/squid-deb-proxy.conf), add the line:

url_rewrite_program /etc/squid-deb-proxy/

As you may have guessed, the helper file needs to be created at /etc/squid-deb-proxy/, containing:

$mirror = "";

$| = 1;
while (<>) {
    @line = split;
    $_ = $line[0];
    if (m/^http:\/\/((?:[a-z0-9]+\.)?archive\.ubuntu\.com)\/(.*)/ &&
        $1 ne $mirror) {
        print "http://" . $mirror . "/" . $2 . "\n";
    } else {
        print $_ . "\n";

Make it executable (chmod +x /etc/squid-deb-proxy/, reload the squid configuration and the changes should immediately be visible. You can check this by looking at the speed, or requesting certain files which do only exist on the local mirror ( in my case).

share|improve this answer

There are better alternatives than Squid for your requirements. See the Apt-Cacher NG which was written for exactly your use-case.

And if you have more than a dozen systems in your network then you should consider to host a (private) Ubuntu mirror.

share|improve this answer
I've been using squid-deb-proxy which works fine and is easily configurable as well. For the clients, I use a method to ignore the proxy if unavailable. Since the network is small (< 5), I do not need to scale too much, it's just that I often forget/ do not bother to configure a local mirror for virtual machines running in RAM. – Lekensteyn Nov 12 '11 at 21:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.