虚拟化容器,大数据,DBA,中间件,监控。

重定向varnish前端用户的URL请求

25 12月
作者:admin|分类:应用管理

重定向varnish前端用户的URL请求


Rewriting and redirecting URLs in Varnish

Rewriting an URL

You can easily rewrite the URL using the regsub() function in VCL. This takes place in vcl_recv.

if (req.http.host ~ "^(www\.)?example\.com" && req.url~ "^/images/") {
  set req.http.host = "images.example.com";
  set req.url = regsub(req.url, "^/images/", "/");
} 

This examples rewrites access to http://www.example.com/images/foo.jpg to http://images.example.com/foo.jpg. This is not visible to the user, but affects how the request to the backend(s) look. This does not affect which backend is used, so images.example.com is not actually resolved.

This is useful to avoid double caching of items available from different URIs. For example, to cache www.example.com and example.com identically, one could use:

set req.http.host = regsub(req.http.host, "^www\.example\.com___FCKpd___1quot;,"example.com");

Requests to www.example.com and example.com will all go to the backend as "example.com" and end up cached by that string.

By the way, regsub() can rewrite any header, really.

Redirection

Varnish does not have any built in support for HTTP redirections so redirection in Varnish can only be accomplished using something of a dirty hack. You trigger an specified error and then pick this error code up in the vcl_error subroutine. See this example for details.
浏览7753 评论0
返回
目录
返回
首页
Linux安装Varnish/varnish原版文档(原版) vsftpd设置多虚拟用户使用相同目录