varnish

varnish 4.0 官方文档翻译17-Misbehaving servers

让人想犯罪 __ 提交于 2019-12-01 04:01:46
Misbehaving servers varnish有个关键特性,为misbehaving(行为不端,诡异的)web服务器或者应用服务器提供保护的能力。 Grace mode 当几个客户端请求同一个页面的时候,varnish只发送一个请求到后端服务器,然后让其他几个请求挂起并等待返回结果;获得结果后,其它请求再复制后端的结果发送给客户端。有些产品中需要调用其他来将请求合并,而varnish自动做这些。 但如果同时有数以千计的请求,那么这个等待队列将变得庞大,这将导致2类潜在问题: 惊群问题(thundering herd problem),即突然释放大量的线程去复制后端返回的结果,将导致负载急速上升; 没有用户喜欢等待; 为了解决这类问题,可以配置varnish在缓存对象因超时失效后再保留一段时间,以给那些等待的请求返回过期的内容(stale content)。 为了提供给用户过期的内容,我们必须先有这些内容。因此我们在VCL中配置如下,使得varnish能在内容过期过后依然保持2分钟: sub vcl_backend_response { set beresp.grace = 2m; } 现在Varnish允许在对象过期后2分钟内提供给客户端。同时varnish也将刷新这个对象。刷新动作是异步发生的,发生在新的对象将替换老对象的同时。 我们可以在vcl

varnish 4.0 官方文档翻译21-Reporting and statistics

谁都会走 提交于 2019-12-01 04:01:32
Reporting and statistics 本部分包括如何查看Varnish正在做什么,从每个http请求流的详细记录到汇总统计计数器。 Logging in Varnish Statistics varnishtop varnishhist varnishstat Logging in Varnish Varnish中一个很棒的特点是工作日志的记录方式。varnish不记录日志到日志文件,而是调用VSL记录到共享内存片段,VSL-varnish共享日志。当这个片段被写完后,varnish开始覆盖老数据。 这种方式比记录到文件快的多得多,并且不需要磁盘空间。除此之外VSL可以给到你需要的尽可能多的信息。 另一方面,如果你忘记有程序实际在写日志到磁盘,日志将会占用过多的磁盘。 varnishlog是可以用来查看varnish记录了什么的程序。varnish提供原生的日志,所有的都被写到日志里。其他一些客户端也能访问日志,一会儿向你展示。 在启动varnish的终端窗口键入varnishlog(varnish-4.0.3: varnishlog -v) 然后回车。 你将看到一些行,缓慢滚动(取决于你的日志量)像这样: 0 CLI - Rd ping 0 CLI - Wr 200 PONG 1273698726 1.0 varnish 主进程检查cache进程,为了查看是否一切ok

varnish 4.0 官方文档翻译17-Hashing

こ雲淡風輕ζ 提交于 2019-12-01 04:01:19
Hashing 实质上,当Varnish存储内容在缓存中时,它也把如何发现这个对象的哈希键和对象一起存储。默认设置的hash键是基于内容的的主机名或者ip地址和URL计算出的。(url+host或者url+ip) 默认的VCL: sub vcl_hash { hash_data(req.url); if (req.http.host) { hash_data(req.http.host); } else { hash_data(server.ip); } return (lookup); } 正如你看见那样,首先检查 req.url 然后如果 req.http.host 存在的话检查 req.http.host 。 需要指出的是在哈希之前varnish不会将hostname或者URL转换成小写,因此“Varnish.org/”和“varnish.org/”理论会导致不同的缓存条目。然而,浏览器,往往小写主机名。 你可以修改hash。这种方式你可以让Varnish根据任意算法提供不同的内容给不同的客户端。 你如果想基于源ip地址提供不同语言的页面给你的用户。你需要一些 根据ip地址判断是哪个国家的VMOD ,然后放在哈希中。看起来像这样: In vcl_recv: set req.http.X-Country-Code = geoip.lookup(client.ip);

varnish 4.0 官方文档翻译5-varnish概况

落花浮王杯 提交于 2019-12-01 04:01:09
The Big Varnish Picture varnish概况 本节将回答这个问题:“varnish”到底是什么,命名的点点滴滴。 varnish两个主要的部分是在varnisd项目中的两个进程。第一个进程被叫做“the manager”,主要功能是告诉你,系统管理员,发生了什么。 第二个进程被叫做“the worker”或者是“the child”,这个进程是实际处理你http请求的进程。 当你启动varnishd,manager进程启动,一旦manager处理完所有的命令行参数,child进程就开始启动了。如果child进程down掉,manager进程会重启child,自动的,无需干预。 这样设计的主要原因是为了安全考虑,manager为了能监听在80端口,以root运行,但是child进程只需要很小的权限。 manager进程是互动的,提供了CLI-命令行接口,可以手动,脚本以及程序调用。CLI提供Varnish处理HTTP请求的几乎全部控制,同时我们已经竭尽全力,以确保你不应该需要重新启动varnish,除非你需要修改最底层的东西。 CLI是远程访问安全的,使用简单灵活的PSK -- Pre Shared Key,所以很容易集成到你的业务或者绑定到你的CMS 所有的这些都包含在 Starting and running Varnish 比如,子进程怎样处理http请求

varnish 4.0 官方文档翻译11-Parameters

℡╲_俬逩灬. 提交于 2019-12-01 04:00:56
Parameters Varnish cache 拥有一个参数的集合,可以影响varnish的行为和性能。基本上所有的参数都可以在Varnish命令行接口( varnishadm )使用param.set关键词来设置。 一些参数,处于安全的目的只读的参数,只能使用-r参数来开启。同时在varnishd的man手册中也有相关的说明 -r param[,param...] Make the listed parameters read only. This gives the system administrator a way to limit what the Varnish CLI can do. Consider making parameters such as user, group, cc_command, vcc_allow_inline_c read only as these can potentially be used to escalate privileges from the CLI. Protecting listen_address may also be a good idea. 我们不建议你调整参数除非你确定你做的是什么。我们努力的使用稳定的默认值,同时varnish使用默认设置应当能处理大多数的工作情况。

varnish 4.0 官方文档翻译6-用户手册-启动运行文档概况

白昼怎懂夜的黑 提交于 2019-12-01 04:00:20
启动和运行varnish 本节包含了启动,运行,停止varnish,命令行参数,如何与运行着的varnish进程进行通信,配置存储和套接字,安全性和如何保护varnish免受攻击。 Security first 安全第一 Command line arguments 命令行参数 The CLI interface CLI接口 VCL programs VCL程序 HTTP requests HTTP请求 Important command line arguments 重要的命令行参数 '-a' listen_address '-a'监听地址 '-f' VCL-file or '-b' backend '-f'VCL配置文件,'-b' 后端server Other options 其他参数 CLI - bossing Varnish around CLI-向varnish发送指令 What can you do with the CLI CLI可以做什么 Storage backends 后端存储 Intro 简介 malloc 基于内存的缓存 file 基于文件的缓存 persistent (experimental) 持久化(实验中) Transient Storage 暂存 Parameters 参数 Sizing your cache 缓存的大小 来源: oschina

Change backend during retry in Varnish 4

旧街凉风 提交于 2019-12-01 03:46:58
I'd like to be able to change the backend on a retry in Varnish 4. We've got this working on a different (older) application using Varnish 3, but I haven't been able to figure it out for v4, nor find much documentation. The setup we want is to have 2 sets of directors - one for the initial request trying a local server in the same datacenter as varnish because this is way faster, and then only if that fails, pick randomly from a different director for servers in other datacenters. In v3, this was easy: sub vcl_recv { if (req.restarts == 0) { set req.backend = defaultdirector; } else { set req

Getting Apache 2.4 access logs to show client IP instead of 127.0.0.1 with Varnish using mod_remoteip

吃可爱长大的小学妹 提交于 2019-11-30 21:46:07
For the life of me, I couldn't get mod_remoteip to get client IPs in my Apache access logs. I'm working on a Virtualmin setup with Varnish 4 installed in front of Apache 2.4.7. How do you get it working? curiouser I finally got the client IPs in the log and I found the last step here: Here are the steps to getting it to work: Get Varnish to pass a header to Apache with the client IP. You do this by including this bit of code (found in this answer ) at the very beginning of your vcl_recv: if (req.restarts == 0) { if (req.http.X-Forwarded-For) { set req.http.X-Forwarded-For = req.http.X

Varnish: how to separately cache pages based on value of a specific cookie

流过昼夜 提交于 2019-11-30 17:33:55
问题 I manage a site that has a single cookie, which we have to use, but will always be one of 9 values (including no value). I'd like to use varnish in front of our application servers, with varnish separately caching a version of each page based on the cookie value. So if we have page /page1, Varnish should separately manage a copy of what /page1 looks like with cookie values a, b, c, d, etc.... Assume we have plenty of memory on the Varnish server to handle storing all pages with all cookie

Regex Syntax changes between POSIX and PCRE

て烟熏妆下的殇ゞ 提交于 2019-11-30 17:18:16
We are currently in the process of upgrading our Varnish Cache servers. As part of the process, we upgraded only one of them to see how it behaves compared to the older versions. Some of the major changes made in this new version is changing the regex engine from POSIX to PCRE. That means that some of our purges (regex purges) have stopped working on the newer server. I was wondering if anyone can list/point me to a list of actual syntax differences between POSIX and PCRE. Or maybe a function that converts a POSIX regex to PCRE regex. This is so that I can convert only the purges going to the