[英]After configuring Varnish how to cache the Web Page for 2 Minutes. (Ubuntu 14.04,Apache,PHP)
I have run the below commands and put the source code into /var/www/html directory. 我运行了以下命令,并将源代码放入/ var / www / html目录。
sudo add-apt-repository ppa:ondrej/php5-5.6
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install php5
sudo apt-get install php5-curl
sudo apt-get install apache2
sudo service apache2 restart
I have followed the below link for configuring the Varnish to cache the webpages. 我已按照以下链接配置Varnish以缓存网页。 But how do i know whether its cached or not.
但我怎么知道它的缓存与否。 Everytime I open the webpage its showing the same webpage.
我每次打开网页时都会显示相同的网页。 How to set expiry for it.
如何为它设置到期日。
I need to cache the webpage for 2 minutes and then expire, so where do I it set those duration. 我需要将网页缓存2分钟然后过期,那么我在哪里设置这些持续时间。
https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-varnish-with-apache-on-ubuntu-12-04--3 https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-varnish-with-apache-on-ubuntu-12-04--3
This is what i get when I say 这就是我说的话
curl -I http://localhost curl -I http:// localhost
HTTP/1.1 200 OK
Server: Apache/2.4.18 (Ubuntu)
ETag: "dd6d718cc03aac91085163fd1927f07a-gzip"
Vary: Accept-Encoding
Content-Type: text/html; charset=UTF-8
Date: Wed, 03 Feb 2016 13:17:48 GMT
X-Varnish: 1965452251 1965452250
Age: 13
Via: 1.1 varnish
Connection: keep-alive
You can tell if varnish is caching the page by looking at the HTTP headers returned from the request. 您可以通过查看请求返回的HTTP头来判断varnish是否正在缓存页面。 The varnish request will have
Age: <seconds>
appended as a header to tell you the age of the request. 清漆请求将附加
Age: <seconds>
作为标题,以告诉您请求的年龄。
Via: 1.1 varnish-plus-v3
Via: 1.1 varnish-plus-v3
Age: 170
You can tell varnish how long to cache the response (if the proper cache headers aren't set on the response itself) by setting the beresp.ttl
value in the configuration file in vcl_backend_response (or vcl_fetch iirc, depending on your varnish version): 您可以通过在vcl_backend_response(或vcl_fetch iirc,取决于您的清漆版本) 中的配置文件中设置
beresp.ttl
值来告诉varnish缓存响应多长时间(如果没有在响应本身上设置正确的缓存头):
set beresp.ttl = 120s;
You can test this by doing 你可以通过这样做来测试
watch HEAD http://localhost:6081
which will repeat the HEAD request to show the headers from the URL every two seconds by default. 这将重复HEAD请求,默认情况下每两秒显示一次URL中的标头。 You'll see Age: increasing until it crosses 120s, when the resource will be returned for the last time and expired from the cache (which means that you can see
Age: 122
even if it is set to 120s). 您将看到Age:增加直到超过120秒,此时资源将最后一次返回并从缓存中过期(这意味着您可以看到
Age: 122
即使它设置为120s)。
Test it with a value shorter than 120s to see it expire quicker. 使用短于120秒的值对其进行测试,以确保其过期更快。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.