OpenLiteSpeed如何开启页面缓存模块?开启缓存后Rewrite规则怎么设置?

老牛  2014-06-19 10:37  阅读 391 views 次 评论 2 条

有一段时间没有关注OpenLiteSpeed开发情况了,今天去官网看了下,目前OpenLiteSpeed最新版本为2014年5月22日发布的OpenLiteSpeed 1.3.2
OpenLiteSpeed开启缓存后可以明显缓解服务器压力,加快页面载入时间,对于流量较大的网站,可以明显提升系统负载能力。
注意:所有模块必须在服务器级别注册后才能进行配置使用,如何注册OpenLiteSpeed模块请阅读老牛博客内相关文章。

OpenLiteSpeed开启页面缓存的方法
1、首先,要开启页面缓存模块必须安装OpenLiteSpeed 1.3以上版本。

2、登录服务器后台后添加模块,操作顺序如下:

WebAdmin console > Configuration > Server > Modules > Add

怎么开启OpenLiteSpeed页面缓存模块
2、填写模块名称为“cache”
怎么开启openLitespeed缓存

3、在Model Parameters内填入以下配置参数(可参照页末参数说明):

enableCache 0
qsCache 1
reqCookieCache 1
respCookieCache 1
ignoreReqCacheCtrl 0
ignoreRespCacheCtrl 0
expireInSeconds 2000
maxStaleAge 1000
enablePrivateCache 1
privateExpireInSeconds 1000
storagePath

4、点击右上角“save”保存即可。注意:本设置是针对服务器级别,但在此基础上OpenLiteSpeed允许对虚拟主机进行单独配置,虚拟主机级别的配置会覆盖服务器级别的配置。

5、OpenLiteSpeed服务器的虚拟主机开启rewrite后,如何配置缓存cache?
进入你的虚拟主机的Rewrite设置页面:

WebAdmin console > Configuration > Virtual Hosts > <em>your virtual host</em> > Rewrite

注意:需要开启Rewrite功能后设置Rewrite规则才能有效!

6、添加Rewrite规则,例如:
(1)缓存目录下所有php文件,缓存周期2分钟

RewriteRule cacheable/(.*\.php)?$ - [L,E=cache-control:max-age=120]

(2)缓存目录下.php, .html, .htm, .feed, .pdf等文件

# this part is for private cache, note that HTTP_COOKIE is for loginuser
 RewriteCond %{REQUEST_METHOD} ^HEAD|GET$
 RewriteCond %{HTTP_COOKIE} loginuser
 RewriteCond %{ORG_REQ_URI} !^/index.php$
 RewriteCond %{ORG_REQ_URI} (\.php|\.html|\.htm|\.feed|\.pdf|/[^.]*)$  [NC]
 RewriteRule .* - [E=cache-control:private,L]

(3)关闭该虚拟主机的Rewrite功能

RewriteRule .* - [E=Cache-Control:no-cache]

OpenLiteSpeed缓存模块配置参数说明:

enableCache = This setting enables or disables public cache. (Set to "1" to enable. Set to "0" to disable.) If both public and private cache are enabled, OpenLiteSpeed will save to and serve from private cache first.
qsCache = This setting enables or disables caching of URIs with query strings. (Set to "1" to enable. Set to "0" to disable.)
reqCookieCache = This setting tells the cache how to react to requests with cookies. If enabled (set to "1"), requests with cookies will be served a response from cache if a cached copy exists. If disabled (set to "0"), requests with cookies, will not be served a response from cache (even if a cached copy of the response exists).
respCookieCache = This setting tells the cache how to treat responses with a Set-Cookie header. If enabled (set to "1"), responses with a Set-Cookie header will be cached. If disabled (set to "0"), responses with a Set-Cookie header will not be cached.
ignoreReqCacheCtrl = Enabling this setting (set to "1") will tell LiteSpeed's cache to ignore any cache control settings in the request.
ignoreRespCacheCtrl = Enabling this setting (set to "1") will tell LiteSpeed's cache to ignore any cache control settings in the response.
expireInSeconds = This setting sets the expiration time (in seconds) for cached resources.
maxStaleAge = This setting sets the maximum time (in seconds) that the cache can serve stale cache. (Stale cache refers to the serving of expired cached resources when a newer resource is not yet available.)
enablePrivateCache = This setting enables or disables private cache. (Set to "1" to enable. Set to "0" to disable.) If both public and private cache are enabled, OpenLiteSpeed will save to and serve from private cache first.
privateExpireInSeconds = This setting sets the expiration time (in seconds) for cached resources in a private cache.
storagePath = This setting sets the directory where cache data will be stored. Paths starting with a / will use an absolute path. Paths without the starting / will be relative to the OpenLiteSpeed root directory. When left blank, cache will be stored in a cachedata directory under the OpenLiteSpeed root.
本文地址:http://xiaohost.com/887.html
版权声明:本文为原创文章,版权归 老牛 所有,欢迎分享本文,转载请保留出处!

发表评论


表情

  1. PHP二次开发
    PHP二次开发 @回复

    学习了。。。

  2. 免费资源部落
    免费资源部落 @回复

    我去试试。。。