【转】通过squid做CND加速

适用: squid-2.7.stable9和squirm-1.0betaB

用来:将优酷,爱奇艺,乐视tv,搜狐视频,凤凰视频,56等等网站的CDN URL重写成内部URL,减少存储占用,增加命中率。

squirm安装:

wget http://squirm.foote.com.au/squirm−1.0betaB.tar.gz
mv squirm−1.0betaB.tar.gz /usr/local/src
cd /usr/local/src/
tar xvf squirm−1.0betaB.tar.gz
cd squirm−1.0betaB
cd regex
./configure
make clean
make
cp −p regex.o regex.h ../
cd ../
make
make install 

squirm.local文件内容:

[root<a href="http://home.51cto.com/index.php?s=/space/159108" target="_blank">@cache</a> ~]# more /usr/local/squirm/etc/squirm.local
# squirm.local.dist
#
# list your client's addresses here.
#
# i.e. the addresses for machines that do 'GET requests',
# but don't include any Squid neighbours

127.0.0
10.1.55
10.1.56

squirm.patterns文件内容:

[root@webcache ~]# more /usr/local/squirm/etc/squirm.patterns
# squirm.patterns.dist
#
# The ordering of lines is this file is critical
# Please see http://www.senet.com.au/squirm/ for examples
## Lines have the form:
#       regex|regexi pattern replacement [[^]accelerator_string[$]]
# or
#       abort filename_extension
#
#
# Examples of valid lines:
#
# regex  ^.*/n32e301\.exe$ http://www.mydomain/path_to/n32e301.exe
# regexi ^.*/n32e301\.exe$ http://www.mydomain/path_to/n32e301.exe
# regex  ^.*/n32e301\.exe$ http://www.mydomain/path_to/n32e301.exe n32e301.exe$
# abort .gif
# abort .html
#regex ^http:\/\/f\.youku\.com\/player\/getFlvPath http://video−srv\.youku\.com.SQUIDINTERNAL\/
#regex http:\/\/[0−9]{1,3}\.[0−9]{1,3}\.[0−9]{1,3}\.[0−9]{1,3}\/youku\/.*?/(.*?)\.flv$ http://v.youku.com.squid/$1.flv
#regex http://[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}/youku/.*/(.*−.*−.*−.*−.*) http://www.youku.com/$1

# tudou video cdn has change to youku,but keep it!
regex http://[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}[^&]*/f4v/.*id=tudou.itemid\=([0−9]*).* http://www.tudou.com.SQUIDTUDOUA/\1
regex http://[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}[^&]*/flv/.*id=tudou.itemid\=([0−9]*).* http://www.tudou.com.SQUIDTUDOUB/\1

#site:sohu tv status:OK date:20141024
regex http://[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}/sohu/[0−9]/[0−9]*/[0−9]*/(.*)\.mp4\?key=.* http://tv.sohu.com.SQUIDSOHUTV/\1.mp4

#site:iqiyi status:OK date:201403120956
regex http://[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}/videos/v/.*/(.*\.f4v)?  http://www.iqiyi.com.SQUIDIQIYI/\1

#site:youku part−tudou status:OK date:201403120956
regex http://[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}/youku/.*/(.*−.*−.*−.*−[^?]*)(.*) http://www.youku.com.SQUIDYOUKU/\1

#site:letv status:OK date:201403122047
regex http://[0−9]{1,3}\.[0−9]{1,3}\.[0−9]{1,3}\.[0−9]{1,3}/[0−9]*/[0−9]*/[0−9]*/letv−uts/[0−9]*/(.*_mp4)/(.*)\.ts\? http://www.letv.com.SQUIDLETVA/\1/\2.mp4
regex http://[0−9]{1,3}\.[0−9]{1,3}\.[0−9]{1,3}\.[0−9]{1,3}/[0−9]*/[0−9]*/[0−9]*/letv−uts/(.*)\.letv\?.*\&video_type=(…)\&.*\&rstart=(.*)\&rend=(.*)  http://www.letv.com.SQUIDLETVB/\1−\3−\4.\2

#site:v.qq.com status:OK date:201403122102
regex http://[0−9]{1,3}\.[0−9]{1,3}\.[0−9]{1,3}\.[0−9]{1,3}/[0−9]*/.*\.qq\.com/.*/[0−9]*/[0−9]*/(.*)\.mp4\? http://v.qq.com.SQUIDQQ/\1.mp4

#site:v.ifeng.com status:OK date:201403130838
regex http://[0−9]{1,3}\.[0−9]{1,3}\.[0−9]{1,3}\.[0−9]{1,3}/data[0−9]*/documentary/[0−9][0−9][0−9][0−9]/[0−9][0−9]/[0−9][0−9]/(.*)\.mp4 http://v.ifeng.com.SQ
UIDIFENG/\1.mp4

#site:56 status:OK date:201403130846
regex http://[0−9]{1,3}\.[0−9]{1,3}\.[0−9]{1,3}\.[0−9]{1,3}/.*\.56\.com/flvdownload/[0−9]*/[0−9]*/(.*)\.flv\?.* http://www.56.com.SQUID56/\1.flv

squid.conf相关配置:

#rewrite store url youku tudou souhu iqiyi

acl store_url url_regex −i ^http:\/\/[0−9]{1,3}\.[0−9]{1,3}\.[0−9]{1,3}\.[0−9]{1,3}\/.*(\.flv|\.m4v\?|\.f4v\?|\.mp4\?|\.ts\?|\.letv\?)
acl store_url_no_domain urlpath_regex −i ^\/(.*\/.*\.flv$)

storeurl_access allow store_url
storeurl_access allow store_url_no_domain
storeurl_access deny all

storeurl_rewrite_program /usr/local/squirm/bin/squirm
storeurl_rewrite_children 5

转自:http://bbs.51cto.com/thread-1098719-1.html

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注