文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

●VCL 中文man page(3)

2023-01-31 01:28

关注
         EXAMPLES(例子)

                  下面这段代码和默认的配置相同,后端服务器主机名设置为“backend.exampl.com
                   backend default {

                    .host = "backend.example.com";

                    .port = "http";

                   }

 
                   sub vcl_recv {

                     if (req.http.x-forwarded-for) {

                     set req.http.X-Forwarded-For = req.http.X-Forwarded-For ", " client.ip;

                   } else {

                     set req.http.X-Forwarded-For = client.ip;

                   }

 
                   if (req.request != "GET" &&

                   req.request != "HEAD" &&

                   req.request != "PUT" &&

                   req.request != "POST" &&

                   req.request != "TRACE" &&

                   req.request != "OPTIONS" &&

                   req.request != "DELETE") {

                     // Non-RFC2616 or CONNECT which is weird.

                     return (pipe);

                     }

                   if (req.request != "GET" && req.request != "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 (lookup);

                   }

 
                   sub vcl_pipe {

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

                     return (pipe);

                   }

 
                   sub vcl_pass {

                     return (pass);

                   }

 
                   sub vcl_hash {

                     set req.hash += req.url;

                     if (req.http.host) {

                       set req.hash += req.http.host;

                     } else {

                       set req.hash += server.ip;

                     }

                     return (hash);

                   }

 
                   sub vcl_hit {

                     if (!obj.cacheable) {

                     return (pass);

                     }

                   return (deliver);

                   }

 
                   sub vcl_miss {

                     return (fetch);

                   }

 
                   sub vcl_fetch {

                   if (!beresp.cacheable) {

                     return (pass);

                   }

                   if (beresp.http.Set-Cookie) {

                     return (pass);

                     }

                   return (deliver);

                   }

 
                   sub vcl_deliver {

                     return (deliver);

                   }

 
                   sub vcl_error {

                   set obj.http.Content-Type = "text/html; charset=utf-8";

                   synthetic {"

                   <?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">

                   <html>

                   <head>

                   <title>"} obj.status " " obj.response {"</title>

                   </head>

                   <body>

                   <h1>Error "} obj.status " " obj.response {"</h1>

                   <p>"} obj.response {"</p>

                   <h3>Guru Meditation:</h3>

                   <p>XID: "} req.xid {"</p>

                   <hr>

                   Varnish cache server

                   </body>

                   </html>

                   "};

                   return (deliver);

                   }

         下面的例子显示一个varnishd实例支持多个独立的站点,基于请求的URL选择使用的后端服务器:
                   backend www {

                     .host = "www.example.com";

                     .port = "80";

                   }

 
                   backend p_w_picpaths {

                     .host = "p_w_picpaths.example.com";

                     .port = "80";

                   }

 
                   sub vcl_recv {

                     if (req.http.host ~ "^(www.)?example.com$") {

                       set req.http.host = "www.example.com";

                       set req.backend = www;

                     } elsif (req.http.host ~ "^p_w_picpaths.example.com$") {

                       set req.backend = p_w_picpaths;

                     } else {

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

 
                   sub vcl_fetch {

                     if (obj.ttl < 120s) {

                     set obj.ttl = 120s;

                     }

                   }

         下面这段代码用来强制缓存带cookies的内容:
                   sub vcl_recv {

                     if (req.request == "GET" && req.http.cookie) {

                     call(lookup);

                     }

                   }

 
                   sub vcl_fetch {

                     if (beresp.http.Set-Cookie) {

                     deliver;

                    }

                   }

         下面代码的作用是利用squidHTTP PURGE模式清理无法使用的目标。
                   acl purge {

                     "localhost";

                     "192.0.2.1"/24;

                   }

 
                   sub vcl_recv {

                     if (req.request == "PURGE") {

                     if (!client.ip ~ purge) {

                       error 405 "Not allowed.";

                     }

                     lookup;

                     }

                   }

 
                   sub vcl_hit {

                     if (req.request == "PURGE") {

                       set obj.ttl = 0s;

                       error 200 "Purged.";

                     }

                   }

 
                   sub vcl_miss {

                     if (req.request == "PURGE") {

                     error 404 "Not in cache.";

                     }

                   }

         SEE  ALSO

                   Varnishd1
        
         HISTORY

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

         这个文档的版权和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

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-后端开发
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯