Varnish 4.0 Official document translation-A brief tutorial

Source: Internet
Author: User
Tags varnish oracle solaris

Varnish 4.0 Brief Tutorial

This part of the tutorial contains the varnish fundamentals. Includes what is varnish, how it works, and also the start and run of varnish. After this part you may want to continue to understand the User Wizard (varnish user boot). If you're reading this on the Web, note the next topic and previous topic on the left side of each page

    • The fundamentals of Web proxy caching with varnish uses varnish as the principle of the web proxies cache

    • Supported Platforms support Platform

    • About the Varnish development process Varnish Development Program Information

    • Getting In touch contact

    • Starting Varnish start using Varnish

    • Put Varnish on port 80 let Varnish monitor on port 80

    • Restarting Varnish again restart Varnish again

    • Backend servers back-end server

    • Peculiarities features

    • What is now? What is now?

The fundamentals of Web proxy caching with varnish uses varnish as the principle of the web proxies cache

Varnish is a cache of HTTP reverse proxies. It receives the request from the client and then attempts to fetch the data from the cache in response to the client's request, and if varnish cannot get the data from the cache in response to the client, it forwards the request to the backend (backend servers), gets the response to be stored at the same time, and finally pays the client.

If varnish has cached a response, it responds much faster than your traditional back-end server, so you need to make as many requests as possible to get the response directly from the varnish cache.

The varnish decides whether to cache the content or get the response from the back-end server. The backend server can varnish cache content through Cache-control in the HTTP response header. Under certain conditions varnish will not cache content, most commonly using cookies. When a client Web request is marked with a cookie, varnish is not cached by default. Many of these varnish functional features can be changed by writing a VCL.

Performance performance

Varnish uses modern, advanced architecture design. Usually depends on the speed of the network, not the performance issue. You should be more concerned about the processing power of your Web application than the performance of varnish.

Flexibility flexible

The key point to improve the performance of varnish cache is its flexible configuration language, VCL. VCL allows you to write rules for how requests are processed. By using rules you can decide what to do with the content, where to get the content, and how to modify the request and response.

Supported platforms supported platforms

Varnish is developed to run current versions of Linux and FreeBSD, and of course it is best to run on these systems. Thanks to these contributors also allow varnish to run on NetBSD, OpenBSD, OS X and a variety of Solaris systems, like Oracle Solaris, Omnios and Smartos.

About the Varnish development processvarnish development process

Varnish is a community-driven project. Varnish Governing Board supervised the development of Varnish, comprising poul-henning Kamp (Architect), Rogier Mulhuijzen (fastly) and Lasse Karstensen (V Arnish software). If you want to make a contribution to varnish, please check this link:

Getting in touch get in touchStarting Varnish

This tutorial assumes that you have already run varnish on ubuntu,debian,enterprise Linux or CentOS. If you want to run varnish on another system, you need to use some brain power to convert it. You will be able to use it later, even on your weird (kinky) system to make sure you have successfully installed varnish (below installing varnish) when you properly install varnish you can use

Service Varnish Start

To start varnish, if Varnish does not start, just the instructions will start varnish, and now your vanish is running up. Use the browser to access with your own machine's IP). The default configuration forwards the request to the Web App. Varnish that the Web application is listening on port 8080. If no web app listens on port 8080 on this machine, varnish will error. When the problem occurs, varnish cache is friendly to provide you with a page like "Error 503 Service Unavailable" You can run the Web app on other ports or other hosts. Now let's edit the configuration file so that he points to a working host. Choose a editor you like, edit/etc/varnish/default.vcl This file is mostly commented out, some not, like this:

VCL 4.0;backend Default {. Host = ""; . Port = "8080";}

Now we change the VCL configuration file, point to an active host, fortunately active, we use this the VCL to replace the following. VCL 4.0;

Backend default {. Host = ""; . Port = "80";}


Service Varnish Reload

Causes the varnish to reload its configuration file. If successful, you will see some directory listings in the browser access You do not see Varnish's official site because your client requested a header that does not have the appropriate host set, and the server responds with the default Folder List.

Put Varnishon port 80 let varnish listen on 80 ports

For testing purposes we have kept varnish running on a high port. Now we let varnish listen on port 80 first stop Varnish:service varnish stop we need to edit the configuration file and then start varnish


Debian/ubuntu is this configuration file/etc/default/varnish. This file looks like this: DAEMONopts= "-a:6081 \ t localhost:6082 \-f/etc/varnish/default.vcl \-s/etc/varnish/secret \-S Mallo c,256m "modified to such DAEMONopts="-a:80 \ t localhost:6082 \-f/etc/varnish/default.vcl \-s/etc/varnish/secret \-S Mall oc,256m "

Red Hat Enterprise Linux/centos

Red Hat/centos configuration file path is/etc/sysconfig/varnish and modified in the same way

Restarting Varnish again

After the modification is complete, you can restart the varnish:

Service varnish start.

Everyone who accesses your website will now pass the varnish.

Original link:

Backend servers back-end service

The varnish has a backend or source server concept. A back-end server is a server that provides content, and varnish is accelerated by using cached content. The first task is to tell Varnish where to get the content. Turn on your favorite editor and open the default configuration file. If you install the default Config file through the source code is this/USR/LOCAL/ETC/VARNISH/DEFAULT.VCL if you install through the package (like Apt-get or yum), it may be this/etc/varnish/default.vcl. If you follow this tutorial, this section of your configuration file looks like this: VCL 4.0;

Backend default {. Host = ""; . Port = "80";}

The configuration file means we have a backend configured in varnish to get content from port 80 on If you don't want to make a image, we need to tweak varnish to get the content from your own source server. We have bound varnish on port 80 and now we need to connect it to the source server. As in the example below, we faked a source server that listens on the localhost 8080 port. VCL 4.0;

Backend default {. Host = "";. Port = "8080";}

Varnish can define a lot of back end, even add this back end to a cluster to achieve the purpose of service equalization, varnish according to the current scheduling algorithm to pick out a backend next, let us see varnish what is unique, and we can use it to do something.

Original link:

Peculiarities characteristics

Varnish cache and some other projects are different, one of which is the VCL you've seen. This machine we will quickly show you the other features you need to know about varnish

Configuration configurations

Varnish use VCL to write configuration files. When varnish uses a configuration file, it converts the configuration file into C code, loads the compiler into C, and then executes the various settings that you adjust, and the VCL rules that you write to process the request will be processed.


Varnish cache has a management console (VARNISHADM), you can connect to the management console by using command Varnishadm, in order to authenticate you need to have/etc/varnish/secret Read permission. You can use Varnishadm to stop, turn on the cache process, load VCL rules, adjust the load balancer, clear the cache, and then exit. Varnishadm built-in commands help you to understand what Varnishadm can do.


Varnish does not log to disk by default, but is recorded in a piece of memory, which is actually a log stream. You can connect to it at any time to see what's going on. Varnish has recorded some information. You can also use Varnishlog to view log streams

What is now?

Varnish a brief tutorial is now over, your varnish should have run now. You should look at Varnish's log, and your VCL configuration file is also coarse. Next, you may need to look at varnish user boot, we can see more varnish detailed features,

Varnish 4.0 Official document translation-A brief tutorial

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: 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.