about 8 years ago

In squid-deb-proxy, add setting to Rewrite request URL. Replace *.archive.ubuntu.com with local mirror

Edit /etc/squid-deb-proxy/squid-deb-proxy.conf, add url_rewrite_program setting

url_rewrite_program /etc/squid-deb-proxy/redirect.php

Create /etc/squid-deb-proxy/redirect.php to processing request URLs

#!/usr/bin/php
#!/usr/bin/php
<?php

$temp = array();

// Extend stream timeout to 24 hours
stream_set_timeout(STDIN, 86400);
$pattern = '/(\w+\.)?archive\.ubuntu\.com/i';
$replacement = 'free.nchc.org.tw';

while ( $input = fgets(STDIN) ) {
        // Split the output (space delimited) from squid into an array.
        $temp = split(' ', $input);

        // Set the URL from squid to a temporary holder.
        $output = $temp[0] . "\n";

        // Check the URL and rewrite it if it matches archive.ubuntu.com
        if ( strpos($temp[0], "archive.ubuntu.com") !== false ) {
                $output = '302:'.preg_replace($pattern, $replacement, $temp[0])."\n";
        }
        echo $output;
}

Let redirect.php be executable

sudo chmod +x /etc/squid-deb-proxy/redirect.php

Restart squid-deb-proxy and monitor if requests URL is redirected

sudo tail -F /var/log/squid-deb-proxy/access.log

The successful redirections should like this:

1429005569.051      1 172.17.0.4 TCP_REDIRECT/302 337 GET http://archive.ubuntu.com/ubuntu/dists/trusty/main/source/Sources.gz - HIER_NONE/- -
1429005569.054      1 172.17.0.4 TCP_REDIRECT/302 343 GET http://archive.ubuntu.com/ubuntu/dists/trusty/restricted/source/Sources.gz - HIER_NONE/- -
1429005569.055      0 172.17.0.4 TCP_REDIRECT/302 341 GET http://archive.ubuntu.com/ubuntu/dists/trusty/universe/source/Sources.gz - HIER_NONE/- -
1429005569.056      0 172.17.0.4 TCP_REDIRECT/302 344 GET http://archive.ubuntu.com/ubuntu/dists/trusty/main/binary-amd64/Packages.gz - HIER_NONE/- -
1429005569.057      0 172.17.0.4 TCP_REDIRECT/302 350 GET http://archive.ubuntu.com/ubuntu/dists/trusty/restricted/binary-amd64/Packages.gz - HIER_NONE/- -
1429005569.058      0 172.17.0.4 TCP_REDIRECT/302 348 GET http://archive.ubuntu.com/ubuntu/dists/trusty/universe/binary-amd64/Packages.gz - HIER_NONE/- -
1429005569.070      0 172.17.0.4 TCP_REDIRECT/302 345 GET http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/source/Sources.gz - HIER_NONE/- -
1429005569.072      0 172.17.0.4 TCP_REDIRECT/302 351 GET http://archive.ubuntu.com/ubuntu/dists/trusty-updates/restricted/source/Sources.gz - HIER_NONE/- -
1429005569.073      0 172.17.0.4 TCP_REDIRECT/302 349 GET http://archive.ubuntu.com/ubuntu/dists/trusty-updates/universe/source/Sources.gz - HIER_NONE/- -
1429005569.074      0 172.17.0.4 TCP_REDIRECT/302 352 GET http://archive.ubuntu.com/ubuntu/dists/trusty-updates/main/binary-amd64/Packages.gz - HIER_NONE/- -
1429005569.075      0 172.17.0.4 TCP_REDIRECT/302 358 GET http://archive.ubuntu.com/ubuntu/dists/trusty-updates/restricted/binary-amd64/Packages.gz - HIER_NONE/- -
1429005569.076      0 172.17.0.4 TCP_REDIRECT/302 356 GET http://archive.ubuntu.com/ubuntu/dists/trusty-updates/universe/binary-amd64/Packages.gz - HIER_NONE/- -
1429005569.200    147 172.17.0.4 TCP_REFRESH_UNMODIFIED/200 1334987 GET http://free.nchc.org.tw/ubuntu/dists/trusty/main/source/Sources.gz - HIER_DIRECT/211.73.64.9 application/x-gzip
1429005569.609     29 172.17.0.4 TCP_REFRESH_UNMODIFIED/200 5736 GET http://free.nchc.org.tw/ubuntu/dists/trusty/restricted/source/Sources.gz - HIER_DIRECT/211.73.64.9 application/x-gzip
1429005570.053    443 172.17.0.4 TCP_REFRESH_UNMODIFIED/200 7926093 GET http://free.nchc.org.tw/ubuntu/dists/trusty/universe/source/Sources.gz - HIER_DIRECT/211.73.64.9 application/x-gzip
1429005570.237    138 172.17.0.4 TCP_REFRESH_UNMODIFIED/200 1743415 GET http://free.nchc.org.tw/ubuntu/dists/trusty/main/binary-amd64/Packages.gz - HIER_DIRECT/211.73.64.9 application/x-gzip
1429005570.259     20 172.17.0.4 TCP_REFRESH_UNMODIFIED/200 16376 GET http://free.nchc.org.tw/ubuntu/dists/trusty/restricted/binary-amd64/Packages.gz - HIER_DIRECT/211.73.64.9 application/x-gzip
1429005570.565    305 172.17.0.4 TCP_REFRESH_UNMODIFIED/200 7589291 GET http://free.nchc.org.tw/ubuntu/dists/trusty/universe/binary-amd64/Packages.gz - HIER_DIRECT/211.73.64.9 application/x-gzip
1429005570.664     48 172.17.0.4 TCP_REFRESH_UNMODIFIED/200 245205 GET http://free.nchc.org.tw/ubuntu/dists/trusty-updates/main/source/Sources.gz - HIER_DIRECT/211.73.64.9 application/x-gzip
1429005570.692     27 172.17.0.4 TCP_REFRESH_UNMODIFIED/200 2710 GET http://free.nchc.org.tw/ubuntu/dists/trusty-updates/restricted/source/Sources.gz - HIER_DIRECT/211.73.64.9 application/x-gzip
1429005570.716     23 172.17.0.4 TCP_REFRESH_UNMODIFIED/200 135611 GET http://free.nchc.org.tw/ubuntu/dists/trusty-updates/universe/source/Sources.gz - HIER_DIRECT/211.73.64.9 application/x-gzip
1429005570.788     70 172.17.0.4 TCP_REFRESH_UNMODIFIED/200 630238 GET http://free.nchc.org.tw/ubuntu/dists/trusty-updates/main/binary-amd64/Packages.gz - HIER_DIRECT/211.73.64.9 application/x-gzip
1429005570.813     24 172.17.0.4 TCP_REFRESH_UNMODIFIED/200 15486 GET http://free.nchc.org.tw/ubuntu/dists/trusty-updates/restricted/binary-amd64/Packages.gz - HIER_DIRECT/211.73.64.9 application/x-gzip
1429005570.860     46 172.17.0.4 TCP_REFRESH_UNMODIFIED/200 343861 GET http://free.nchc.org.tw/ubuntu/dists/trusty-updates/universe/binary-amd64/Packages.gz - HIER_DIRECT/211.73.64.9 application/x-gzip
← Install robotframework/robotframework-ride on windows 64bit go-ipfs on windows →
 
comments powered by Disqus