Varnish Status Engine 1

Source: Internet
Author: User
Tags varnish

Vcl:

State Engine: A certain degree of correlation between the engines; if a previous engine can have a variety of downstream engine, the upstream engine needs to use return to indicate

Downstream engine to be transferred  

Vcl_recv
Vcl_hash
Vcl_hit
Vcl_miss
Vcl_fetch
Vcl_deliver
Vcl_pipe
Vcl_pass
Vcl_error

Programming language Syntax:

(1)//, #,/* */for comments; it will be ignored by the compiler

(2) Sub $name: Used to define subroutines

Example: Sub Vcl_recv {

}

(3) No circular operation is supported

(4) There are many built-in variables, and the callable position of the variable is closely related to the state engine.

(5) Support termination statement, return (action), but no return value

(6) The entire language is only valid for a "domain", called "domain" dedicated

(7) Operator: =, = =, ~,!, &&, | |

Conditional Judgment Statement:

if (condtion) {

} else {

}

Variable assignment: Set name=value unset name

Req.http.HEADER: Invokes the specified header header of the HTTP protocol in the request message

Example: Req.http.x-forwarded-for req.http.Auhtorization Req.http.cookie

Req.request: Request method

State engine Workflow (V3):

VCL_RECV--Vcl_hash--Vcl_hit-Vcl_deliver

VCL_RECV--Vcl_hash--and Vcl_miss--vcl_fetch--Vcl_deliver

VCL_RECV--Vcl_pass--Vcl_fetch-Vcl_deliver

VCL_RECV-Vcl_pipe

Define a configuration file, copy it first, CP/ETC/VARNISH/DEFAULT.VCL/ETC/VARNISH/TEST.VCL

VIM/ETC/VARNISH/TEST.VCL Add the following configuration under sub Vcl_deliver engine

Obj.hits (built-in variable): The number of times this request object was hit from the cache

The above command is to add X-cache = "hit" header if it hits, then add X-CAHCE = "MISS" header in the dead

Varnishadm-s/etc/varnish/secret-t 127.0.0.1:6082 Landing varnish

Compile and load the new configuration file:

Access to varnish on the client

Hit!

Built-in variables in varnish:
Variable type:
Client
Server
Req
Resp
Bereq
Beresp
Obj
Storage

Bereq.http.HEADERS: The specified header of a request message sent by varnish to backend server

Bereq.request: Request method

Bereq.backend: Indicates the back-end host to invoke

Beresp.status: Status code of the response of the backend server

Beresp.http.HEADER: Header of the message responding from backend server

Beresp.ttl: The remaining lifetime of the content of the backend server response

Obj.ttl: The TTL value of the object

Obj.hits: The number of times this object was hit from the cache

VIM/ETC/VARNISH/TEST.VCL plus a variable

Varnish's own IP address has been added to the browser debug interface.

The following rules are built into the sub Vcl_recv engine in the VARNISH4 version by default

sub vcl_recv {
if (Req.method = = "PRI") {
*/We do not support SPDY or http/2.0 */
return (synth (405));

if (Req.method! = "GET" &&
Req.method! = "HEAD" &&
Req.method! = "PUT" &&
Span style= "FONT-SIZE:14PT;" > Req.method! = "POST" &&
Req.method! =" TRACE "&&
Req.method! = "Options" &&

return (pipe);

if (Req.method! = "GET" && req.method! = "HEAD") {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.Authorization | | req.http.Cookie) {
/* not cacheable by default */
return (pass);
}
return (hash);
}

Varnish Status Engine 1

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.