●VCL 中文man page(3)
发布时间:2019-07-15 10:49:39编辑:auto阅读(1281)
下面这段代码和默认的配置相同,后端服务器主机名设置为“backend.exampl.com”
.host = "backend.example.com";
if (req.http.x-forwarded-for) {
set req.http.X-Forwarded-For = req.http.X-Forwarded-For ", " client.ip;
set req.http.X-Forwarded-For = client.ip;
if (req.request != "GET" &&
req.request != "TRACE" &&
req.request != "OPTIONS" &&
req.request != "DELETE") {
// Non-RFC2616 or CONNECT which is weird.
if (req.request != "GET" && req.request != "HEAD") {
// We only deal with GET and HEAD by default
if (req.http.Authorization || req.http.Cookie) {
// Not cacheable by default
# Note that only the first request to the backend will have
# X-Forwarded-For set. If you use X-Forwarded-For and want to
# have it set for all requests, make sure to have:
# set req.http.connection = "close";
# here. It is not set by default as it might break some broken web
# applications, like IIS with NTLM authentication.
set req.hash += req.http.host;
set req.hash += server.ip;
if (beresp.http.Set-Cookie) {
set obj.http.Content-Type = "text/html; charset=utf-8";
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<title>"} obj.status " " obj.response {"</title>
<h1>Error "} obj.status " " obj.response {"</h1>
<p>"} obj.response {"</p>
<h3>Guru Meditation:</h3>
<p>XID: "} req.xid {"</p>
下面的例子显示一个varnishd实例支持多个独立的站点,基于请求的URL选择使用的后端服务器:
.host = "www.example.com";
.host = "p_w_picpaths.example.com";
if (req.http.host ~ "^(www.)?example.com$") {
set req.http.host = "www.example.com";
} elsif (req.http.host ~ "^p_w_picpaths.example.com$") {
set req.backend = p_w_picpaths;
error 404 "Unknown virtual host";
The following snippet demonstrates how to force a minimum TTL for
all documents. Note that this is not the same as setting the
default_ttl run-time parameter, as that only affects document for
which the backend did not specify a TTL:::
下面这段代码用来强制缓存带cookies的内容:
if (req.request == "GET" && req.http.cookie) {
if (beresp.http.Set-Cookie) {
下面代码的作用是利用squid的HTTP PURGE模式清理无法使用的目标。
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
if (req.request == "PURGE") {
if (req.request == "PURGE") {
error 404 "Not in cache.";
Varnishd(1)
The VCL language was developed by Poul-Henning Kamp in cooperation with Verdens Gang AS, Linpro AS and Varnish Software. This manual page was written by Dag-Erling Smørgrav and later edited by Poul-Henning Kamp and Per Buer.
这个文档的版权和varnish自身的版本一样,请看LICENCE。
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2008 Linpro AS
* Copyright (c) 2008-2010 Redpill Linpro AS
* Copyright (c) 2010 Varnish Software AS
关键字: