« 如何:在你的Mac上玩超级玛莉 | Home | vsftpd + virtual user + pam_mysql »

October 8, 2009

Varnish tips

很久没写点什么了,不多废话。

今天把充当反向代理很久了的 Squid 全面换成 Varnish。

安装: www/varnish
完成以后编辑 ${LOCALBASE}/etc/varnish/default.vcl

怎么指定特定的IP在访问特定域名时跳转:

acl ip2redir {
    "192.168.1.123";
}

在 vcl_recv 里面加入:

if (client.ip ~ ip2redir && req.http.host ~ "^www.example.org$") {
    error 702 "Found";
}

再在 vcl_error 里面加入:

if (obj.status == 702) {
    set obj.http.Location = "http://www.example.com" req.url;
    set obj.status = 302;
    deliver;
}
即可,req.url 是为了方便把请求的 path 部分同时转给目的服务器。

另外还是提一下,varnishd 的启动配置可以在位于 /etc 下rc.conf(5) 里面改,比如监听的端口改成 80 什么的。

监控服务器的访问,可以先用 rc scirpt 启动 varnishlog 再运行 varnishlog(1)。

No TrackBacks

TrackBack URL: http://mt.opensource.org.cn/cgi-bin/mt/mt-tb.fcgi/493

Leave a comment