如何将* .example.com重写为www.example.com?

在我的networking中,我有一些Ubuntu机器需要从nl.archive.ubuntu.com下载文件。 由于多次下载都是浪费时间,所以我设置了一个用于caching数据的squid代理。

此代理的另一个用途是nl.archive.ubuntu.com archive.ubuntu.com*.archive.ubuntu.com请求重写为nl.archive.ubuntu.com因为此镜像比美国镜像快。

这工作得很好,但最近我的caching机安装后,configuration丢失了。 我记得有一个单独的Perl程序来处理这个重写。

我如何设置这样一个鱿鱼代理重写主机*.example.comwww.example.com和caching后者的结果?

要将来自*archive.ubuntu.com镜像请求重写到nl.archive.ubuntu.com ,您需要创build一个重写助手并configurationsquid使用此助手来重写请求。

在鱿鱼configuration(例如/etc/squid-deb-proxy/squid-deb-proxy.conf ),添加行:

 url_rewrite_program /etc/squid-deb-proxy/rewrite.pl 

正如你可能已经猜到的,这个助手文件需要在/etc/squid-deb-proxy/rewrite.pl创build,其中包含:

 #!/usr/bin/perl $mirror = "nl.archive.ubuntu.com"; $| = 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"; } } 

使其可执行( chmod +x /etc/squid-deb-proxy/rewrite.pl ),重新加载鱿鱼configuration,应立即可见变化。 你可以通过查看速度来检查,或者请求只存在于本地镜像上的某些文件( http://nl.archive.ubuntu.com/rsyncscript.txt )。

根据你的要求,有比Squid更好的select。 请参阅适用于您的使用案例的Apt-Cacher NG 。

如果你的networking中有十几个系统,那么你应该考虑托pipe一个(私有的)Ubuntu 镜像 。