简体   繁体   English

配置Varnish之后如何将网页缓存2分钟。 (Ubuntu 14.04,Apache,PHP)

[英]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.

相关问题 在Ubuntu中从源代码安装Apache和PHP后为MySQL配置PHP - Configuring PHP for MySQL after installing Apache & PHP from source in Ubuntu 在Ubuntu 14.04上的Apache服务器上找不到页面错误 - Page not found error on apache server on ubuntu 14.04 Ubuntu 14.04,Apache 2.4.10。 无法解析php - Ubuntu 14.04, apache 2.4.10. Not parse php 升级到ubuntu 14.04后使用aigaion2开发PHP - php with aigaion2 after upgrade to ubuntu 14.04 如何使用清漆页面缓存在magento上启用geoip - How to Enable geoip on magento with varnish page cache 部署到云端后,Google App Engine和PHP空白页。 (Ubuntu 14.04 LTS) - Google App Engine and PHP Blank Page after deploying to the cloud. (Ubuntu 14.04 LTS) 如何在 Ubuntu 14.04 中使用 XAMPP 为 PHP Apache Cassandra 本地服务器安装和连接 DataStax 驱动程序 - How to install and connect DataStax Driver for PHP Apache Cassandra local server with XAMPP in Ubuntu 14.04 使用Varnish缓存动态页面 - Cache dynamic page with Varnish 如何从 Apache PHP 脚本(Ubuntu 14.04)向守护进程发送信号 SIGUSR1 - How to send signal SIGUSR1 to daemon from Apache PHP script (Ubuntu 14.04) 如何在 Ubuntu 14.04 中安装 PHP intl 扩展 - How to install PHP intl extension in Ubuntu 14.04
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM