Two: 5. Configure varnish to support multiple back-end domain names

Source: Internet
Author: User
Tags varnish
Configure varnish to support multiple backend domain names 2011-07-12-web Development Tags: caching varnishIn the use of varnish will involve proxy multiple backend domain names (or Web sites), you can determine the requested URL to set the corresponding backend can solve the problem.
To varnish the official documentation of the example (Https://www.varnish-cache.org/docs/trunk/reference/vcl.html#examples):

#后端服务器www
backend www {
     . host = "www.example.com";
     . Port = "n";

#后端服务器images
backend Images {
     . host = "images.example.com";
     . Port = "n";

Sub Vcl_recv {
     #如果host为www. example.com, set back-end server to WWW, (? i) to indicate that the matching pattern is case-insensitive
     if (req.http.host ~ "(? i) ^ (www.)? example.com$ ") {
          set req.http.host =" www.example.com ";
          Set req.backend = www;
     #如果为images. example.com, set back-end server to images
     } elsif (req.http.host ~ "(? i) ^images.example.com$") {
          set Req.backend = images;
     } else {
          error 404 ' Unknown virtual host ';
     }
}

Also in the Vcl_hash function must be added
Hash_data (Req.http.host);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.