Large Web site IT technology architecture

Source: Internet
Author: User
Tags varnish netscaler

1. Varnish Reverse proxy Server (external client requests resources from intranet server)

Mode:

Proxy Cache , the extranet client cannot find the requested resource in varnish, varnish requests the resource to the upstream Apache and then passes it to the client and caches the resource at the same time;

Bypass Cache , the extranet client cannot find the requested resource in varnish, varnish the client's request to the upstream apache,client to get the resource and return the resource to varnish;


recently, the company to do activities to promote, traffic explosion, the back-end server pressure Alexander, resulting in the user's request response time to prolong, the customer complained loud.
to solve problems as quickly as possible, while arranging for staff to continuously optimize the backend code, considerNginxbefore adding the varnish cache layer, only the part of the dynamic request past, directly reduce the back-end server pressure.
in actual use, really feel the power of varnish server! After the constant tuning cache hit ratio, the backend server CPU directly from 80% to 20%, and then the large concurrent front end can also be directly digested, the back-end server indicates no pressure. With this thing, you can no longer write scheduled tasks in the background, and constantly regenerate static pages, the direct drop of the cache is finished! In addition, Varnish also supports a "sacred mode", when the back-end server error returns 500, the varnish can continue to return to the past cached content, for the user to block some errors, which is sometimes really a lifeline.
but at the same time, also trip to n many pits, varnish in the VCL language is too strong and flexible, slightly use bad will be shot. most of the varnish profiles that are open online are a big copy and cannot be used directly for production . After studying for a few days, I looked through a lot of information, and then finally solved the problems we encountered.

Varnish need to cache data on multiple servers, you need to varnish map all URLs to a backend Web server.

Varnish Basic configuration:

  1. Backend webserver  {  

  2. .host "127.0.0.1"

  3. .port " style= "margin:0px;padding:0px;border:0px;vertical-align:baseline;background-color:transparent;" ;  

  4. .connect_timeout  =  4s

  5. .first_byte_timeout  =  5s

  6. . Between_bytes_timeout  =  20s  ;

  7. }

This block configuration is used to define a back-end server that varnish default access, and when varnish needs to obtain data from the back-end server, it accesses its 80 port.

course varnish can also define multiple back-end Web servers for load balancing purposes. (or set up a Web server that is a VIP , the service IP, with a Web cluster in the background)

. Connect_timeout defines the time to wait for the backend of the connection

. First_byte_timeout defines the time to wait for the first byte to be transmitted from backend

. Between_bytes_timeout defines a time interval of two bytes

Of course, you can also add a backend to access the local 8090 port, assuming that the port provides image services (image server).

  1. backend img  {  

  2. . Host  =  "127.0.0.1"  ; ( the IP can also be a VIP, performing a back-end picture cache server )

  3. . Port  =  "8090"  ;

  4. }

When matching the URL of img , the request is sent to the backend IMG defined above, and other requests are sent to backend webserver.

  1. Sub Vcl_recv {

  2. if (req.url ~ "^/img/") {

  3. Set Req.backend  =  img  ;

  4. } else {

  5. Set Req.backend  =  webserver  .

  6. }

  7. }


In the enterprise production environment, varnish can configure multiple units, the public network with a VIP to receive client requests, load balancing devices (Citrix's netscaler,f5 big-IP, The native open source software LVS distributes the request VIP connection through some load balancing policy (URL Hash,round-robin, etc.) to the backend Varnish service resource pool.

Of course, you can also use multiple VIPs (the VIP corresponds to the same domain name), each VIP behind the same varnish service resource pool, or a different varnish service resource pool.

For example, Citrix NetScaler can be configured on the above vip-1 corresponding to 10 varnish,vip-2 corresponding to 10 units of the same varnish, or vip-2 corresponding to different varnish.

Large Web site IT technology architecture

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.