有一段时间没有关注OpenLiteSpeed开发情况了,今天去官网看了下,目前OpenLiteSpeed最新版本为2014年5月22日发布的OpenLiteSpeed 1.3.2。
OpenLiteSpeed开启缓存后可以明显缓解服务器压力,加快页面载入时间,对于流量较大的网站,可以明显提升系统负载能力。
注意:所有模块必须在服务器级别注册后才能进行配置使用,如何注册OpenLiteSpeed模块请阅读老牛博客内相关文章。
OpenLiteSpeed开启页面缓存的方法
1、首先,要开启页面缓存模块必须安装OpenLiteSpeed 1.3以上版本。
2、登录服务器后台后添加模块,操作顺序如下:
1 | WebAdmin console > Configuration > Server > Modules > Add |
3、在Model Parameters内填入以下配置参数(可参照页末参数说明):
1 2 3 4 5 6 7 8 9 10 11 | 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设置页面:
1 | WebAdmin console > Configuration > Virtual Hosts > <em>your virtual host</em> > Rewrite |
注意:需要开启Rewrite功能后设置Rewrite规则才能有效!
6、添加Rewrite规则,例如:
(1)缓存目录下所有php文件,缓存周期2分钟
1 | RewriteRule cacheable/(.*\.php)?$ - [L,E=cache-control:max-age=120] |
(2)缓存目录下.php, .html, .htm, .feed, .pdf等文件
1 2 3 4 5 6 | # 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功能
1 | RewriteRule .* - [E=Cache-Control:no-cache] |
OpenLiteSpeed缓存模块配置参数说明:
1 2 3 4 5 6 7 8 9 10 11 | 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. |
原文链接:https://xiaohost.com/887.html,转载请注明出处。
评论2