`
阅读更多

Controlling the Expiration of Content in Caches¶
Module: mod_expire

Description:
mod_expire controls the Expire and Cache-Control: max-age headers in the Response Header of HTTP/1.0 and HTTP/1.1
messages. It is useful to set it for static files which should be cached
aggressively like images, stylesheets or similar.

Options:
expire.url
assigns a expiration to all files below the specified path. The
specification of the time is made up of:

<access|modification> <number> <years|months|days|hours|minutes|seconds>

where access means time of user access and modification means time of file modification. Follows the syntax used by mod_expire in Apache 1.3.x and later. (See: http://httpd.apache.org/docs/1.3/mod/mod_expires.html) Example:

    expire.url = ( "/images/" => "access 1 hours" )

Example to include all sub-directories:

    $HTTP["url"] =~ "^/images/" {
         expire.url = ( "" => "access 1 hours" )
    }

Troubleshoot:
It is known that mod_expire may not work due to an incorrect order of loading of modules. One instance is that mod_expire is loaded after mod_fastcgi. The solution is simple, it is to move mod_expire within the modules array in front of mod_fastcgi. Note: The order of the modules is loaded from top to bottom.

Symptoms of the above scenario is the server starts up fine but fails to serve content.

In 1.4.13 (and probably others) you must load mod_expire BEFORE mod_compress. Otherwise, expires headers will NOT be output when serving a compressed document.

Also, expire.url = ( "/images/" => "access 1 hours" ) did not work for me. I had to use the second form.

I tested in 1.4.18 and above two problem(one is order mod_expire and mod_compress and the other is expire time specification setting) is not appeared.

文章来源:http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModExpire

我的测试:

过期时间(expire)是HTTP响应(response)的头部控制信息,浏览器会在指定过期时间内使用本地缓存,不用重新加载,对应的缓存对象主要是静态文件,如css,image, java; 可以在服务器端进行全局设置,也可以应用端进行设置,这里我会说下服务器端的设置


打开:"mod_expire",去掉前面的注释:"#"

#========================================================================================#
#------------------配置 expire 模块 设置过期时间----------------------------------------------#
#-----语法:<access|modification> <number> <years|months|days|hours|minutes|seconds>
#========================================================================================#
#data2及其子目录的规则:访问过期2小时

$HTTP["url"] =~ "^/data2/" {
#expire.url = ( "" => "modification 2 hours" ) #这个在浏览器访问会一次200(读取服务器文件) 一次304(读取本地缓存)轮流替换
expire.url  = ( "" => "access 6 hours" ) #这个第一次200 第二次304 以后就一直本地
}

有关Etag和Expires的文档,参见这里

所以mod_expire要配合Etag使用

etag 默认的配置 是根据系统的inode 可以选择为:modified-time
如果服务器有多台的话,就得配置:
etag.use-inode = "disable"
etag.use-mtime          = "enable" #使用修改时间,每台服务器的修改时间得一致,才能达到目的
我们现在配置的是:

#启用etag
static-file.etags =  "enable"
#使用文件修改时间
etag.use-mtime =  "enable"
#禁用系统inode
etag.use-inode = "disable"


另外官方解释:

Description
defines if the ETag generation algorithm will use the inode value of the file.
If you have multiple lighttpd servers serving static content then you should use

etag.use-inode = "disable"

So that the ETag value is consistent across the lighttpd clusters. Otherwise you will generate lesser number of 304 responses
Do make sure that the static content on all your clusters have the same mtime (modified-time)

Default: enabled

分享到:
评论

相关推荐

    linux 下配置 Apache 详解

    从单纯的HTML静态服务(core),到复杂的动态页面服务(core + php, core + resin, core + php + mod_gzip, core + resin + mod_expire)。 本文主要从简化安装==&gt;性能调优==&gt;维护方便的角度,介绍了WEB服务的规划、...

    ESSP_nt64_14.2.19.0_Expire.7z

    杀毒软件直装版

    taskwarrior-tag_expire-hook:一个即将过期的启动挂钩(状态

    taskwarrior-tag_expire-hook 这个 taskwarrior 钩子脚本旨在 弄湿我的脚,学习钩子脚本是如何工作的,从一个基本的开始 为用户提供一个简单的替代方法来分配一个直到:日期值,即在到期:日期之后,对于那些在到期...

    Apache的学习笔记

    版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明http://www.chedong.com/tech/apache_install.html关键词: apache install php resin mod_gzip mod_expire webalizer ...

    微信支付与支付宝支付

    项目采用的是Springboot 和 cloud maven构建 将微信的APPID等参数带入WxConfigUtil中即可 支付宝的参数带入AlipayConfig中即可。然后自己设置好回调地址,最终价格,body 就可以了

    ecshop扫码付款-已成功感谢提供者

    修复个小BUG wxpay.php $input-&gt;SetTime_expire(date("YmdHis", time() 此行注释掉不然微信反馈参数错误,Time_expire为非必须项目

    tibeecompare:用于比较执行跟踪的应用程序

    exit hrtimer_expire_entry hrtimer_expire_exit irq_handler_entry irq_handler_exit inet_sock_local_in inet_sock_local_out lttng_statedump_end lttng_statedump_process_state lttng_state

    furnish-ecommerce:全栈电子商务平台

    Node.js 表示React.js Redux MongoDB地图集快速开始 :rocket: :rocket: :rocket: # set all environment variables below in .env file- MONGO_URI- FILE_UPLOAD_PATH- JWT_SECRET- JWT_EXPIRE- JWT_COOKIE_EXPIRE-...

    任务狂:个人吉拉

    Taskaholic v1.0.0 一个针对类别和时间跟踪的待办Web应用程序,面向面向任务的个人。 当地发展您可以使用Kubernetes或Docker Compose进行本地开发。...INITDB_DATABASE=JWT_SECRET=JWT_EXPIRE=30dJWT_COOKIE_EXPIRE=30

    启动试用期过期软件脚本

    我下载了Navicat的试用版,然后过期了,我就写了一个脚本,把系统时间设置为过期前的时间,...before_expire_date='2017-08-27' #exe文件路径 path=r'C:\"Program Files"\PremiumSoft\"Navicat for MySQL"\navicat.exe'

    Linux Page Cache参数调优

    (1)数据存在的时间超过了dirty_expire_centisecs(默认30s)时间 (2)脏数据所占内存 /(MemFree + Cached – Mapped) &gt; dirty_background_ratio。也就是说当脏数据所占用的内存占(MemFree + Cached – Mapped...

    [计算机毕设]基于jsp的作业管理系统设计与实现(源代码+项目报告).zip

    应交日期 name=”tea_hw_expire” 难易度 name=”tea_hw_diff_easy” 是否开启 name=”tea_hw_open” 布置日期 (利用hidden控件传递 name=”tea_hw_date”) (5) 向控制器传递参数 利用hidden传递 name=”cou_no”...

    Expire Template_欧美扁平化网页PSD模板美工UI.zip

    Expire Template_欧美扁平化网页PSD模板美工UI.zip

    e-commerce:MERN Stack项目

    电子商务 使用MERN Stack和Redux构建的电子商务平台。 感谢Brad Traversy,这是MERN的...JWT_COOKIE_EXPIRE =30d JWT_SECRET="write your jwt secret" JWT_EXPIRE=30d PAYPAL_CLIENT_ID="write paypal client id" 安

    Thinkphp3.2.3 Redis session驱动

    'SESSION_EXPIRE' =&gt; 120, //session有效期(单位:秒) 0表示永久缓存 'SESSION_PREFIX' =&gt; 'session_', //session前缀 'SESSION_REDIS_HOST' =&gt; '127.0.0.1', //分布式Redis,默认第一个为主服务器 'SESSION_REDIS...

    Expire Template_企业网站PSD扁平化网页模板美工UI整站.zip

    Expire Template_企业网站PSD扁平化网页模板美工UI整站.zip

    burger-reviews:这需要汉堡评论并制作图表

    汉堡评论 这需要汉堡评论并制作图表。 设置 我建议使用docker-compose ,但是没有它也可以使用它。您可以创建一个Google表单并将其链接为电子表格,这...这限制了您每TOKEN_EXPIRE_TIME可以收到多少个请求。默认值为

    expire:Expire旨在尽可能方便地使用缓存

    Expire旨在使使用缓存尽可能方便。 有三种创建缓存的方法,分别是MemoryCache,RedisCache或MemcachedCache。如何使用?安装跑步: pip install expirepip install git+https://github.com/howie6879/expire.git...

    easy-cache:Laravel可以轻松进行缓存的缓存特征

    您可以为每个函数定义一个static变量$expire public class test (){ use EasyCacheTrait ; public function __construct (){ $ this -&gt; default_expire = 1 ; //change default expire time (min) } public ...

Global site tag (gtag.js) - Google Analytics