使用Ngnix和Squid实现页面301跳转
(2011-09-14 16:08)
一、nginx 的rewrite测试
测试实现www.test1.com/* 自动跳转到www.test2.com/*
- 配置代码:
- server
- {
- listen 80;
- server_name test1.com;
- index index.html index.shtml index.php;
- root /data/webroot/bitauto;
- if ($host ~* (.*)\.test1\.com) {
- set $sub_name $1;
- rewrite ^/(.*)$ http://$sub_name.test2.com/$1 permanent;
- }
二. squid url rewrite with jesred
1)主要配置文件
/usr/local/squid/etc/jesred.conf (设置一些配置选项)
/usr/local/squid/etc/jesred.acl (配置哪些来源的ip可以被jesred rewrite,一般设置为 0.0.0.0/0,而通过squid自身控制rewrite条件)
/usr/local/squid/etc/jesred.rules (实际的rewrite规则)
2. squid.conf片断:
- url_rewrite_program usr/local/squid/etc/libexec/jesred
- url_rewrite_children 20
- url_rewrite_host_header off
3附加说明
默认,jesred(或是其它的些rewrite工具)是作隐式的(透明地)url rewrite,即 从 url1 -> url2时,HTTP Ret Code还是会200,
客户端觉查不到有跳转的发生;
如果需要返回显示的跳转,HTTP RetCode 301或是302,即需要对rewrite规则进行小的修改
regexi ^http://(.*).163.com/(.*\.wma)\?.* http://\1.163.com/\2 #此为隐式跳转
regexi ^http://(.*).163.com/(.*\.wma)\?.* 302:http://\1.163.com/\2 #此为显式跳转
4.测试
测试实现www.test1.com/* 自动跳转到www.test2.com/*
编辑 /usr/local/squid/etc/jesred.rules
- regexi ^http://www\.test1\.com/(.*)$ 301:http://www.test2.com/\1


