通过web服务器达到页面缓存和负载均衡的作用
window下安装apache服务器,httpd-2.2.25-win32-x86-no_ssl.msi
,一直下一步,如果遇到如图提示:
查找得知出现此异常的原因是80端口号被占用
解决方法: 修改apache默认端口号(关闭占用80端口号的进程)
在apache安装目录下的conf文件夹下找到httpd.conf文件,将Listener端口号由原来的80改为81。
访问package share页面,登陆进入,搜索框搜索dispatcher,然后根据自己的web服务器版本选择对应版本的dispatcher,下载。dispatcher-apache2.2-windows-x86-4.1.0.zip
disp_apache2.2.dll
拷贝至apache安装目录下的module目录下; dispatcher.any
拷贝至apache安装目录下的conf目录下。配置dispatcher.any,指定缓存路径,缓存保存位置等,参数详解:
/farms块定义一系列的farms或者websites。每个/farms块定义了:
/farms
{
$include "myFarm.any"
}
/clientheaders
{
"*"
}
# The load will be balanced among these render instances
/renders
{
/rend01
{
# Hostname or IP of the render
/hostname "localhost"
# Port of the render
/port "4502"
# Connect timeout in milliseconds, 0 to wait indefinitely
# /timeout "0"
}
/rend02
{
/hostname "121.40.140.2"
/port "4502"
# /timeout "0"
}
}
# The filter section defines the requests that should be handled by the dispatcher.
# The globs will be compared against the request line, e.g. "GET /index.html HTTP/1.1".
/filter
{
# Deny everything first and then allow specific entries
/0001 { /type "deny" /glob "*" }
# Open consoles
# /0011 { /type "allow" /glob "* /admin/*" } # allow servlet engine admin
# /0012 { /type "allow" /glob "* /crx/*" } # allow content repository
# /0013 { /type "allow" /glob "* /system/*" } # allow OSGi console
# Allow non-public content directories
/0021 { /type "allow" /glob "* /apps/*" } # allow apps access
/0022 { /type "allow" /glob "* /bin/*" }
/0023 { /type "allow" /glob "* /content*" } # disable this rule to allow mapped content only
/0024 { /type "allow" /glob "* /libs/*" }
# /0025 { /type "deny" /glob "* /libs/shindig/proxy*" } # if you enable /libs close access to proxy
/0026 { /type "allow" /glob "* /home/*" }
/0027 { /type "allow" /glob "* /tmp/*" }
/0028 { /type "allow" /glob "* /var/*" }
# Enable specific mime types in non-public content directories
/0041 { /type "allow" /glob "* *.css *" } # enable css
/0042 { /type "allow" /glob "* *.gif *" } # enable gifs
/0043 { /type "allow" /glob "* *.ico *" } # enable icos
/0044 { /type "allow" /glob "* *.js *" } # enable javascript
/0045 { /type "allow" /glob "* *.png *" } # enable png
/0046 { /type "allow" /glob "* *.swf *" } # enable flash
/0047 { /type "allow" /glob "* *.jpg *" } # enable jpg
/0048 { /type "allow" /glob "* *.jpeg *" } # enable jpeg
# Enable features
/0062 { /type "allow" /glob "* /libs/cq/personalization/*" } # enable personalization
# Deny content grabbing
/0081 { /type "deny" /glob "GET *.infinity.json*" }
/0082 { /type "deny" /glob "GET *.tidy.json*" }
/0083 { /type "deny" /glob "GET *.sysview.xml*" }
/0084 { /type "deny" /glob "GET *.docview.json*" }
/0085 { /type "deny" /glob "GET *.docview.xml*" }
/0086 { /type "deny" /glob "GET *.*[0-9].json*" }
# /0087 { /type "allow" /glob "GET *.1.json*" } # allow one-level json requests
# Deny query
/0090 { /type "deny" /glob "* *.query.json*" }
}
Adobe推荐/libs,/etc,/crx,/admin,/var,/tmp,/home,/apps和其它的一些URIS都不能被外部访问。/docroot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"
# Sets the level upto which files named ".stat" will be created in the
# document root of the webserver. When an activation request for some
# page is received, only files within the same subtree are affected
# by the invalidation.
/statfileslevel "2"
# Flag indicating whether to cache responses to requests that contain
# authorization information.
/allowAuthorized "0"
/rules
{
/0000
{
# the globbing pattern to be compared against the url
# example: * -> everything
# : /foo/bar.* -> only the /foo/bar documents
# : /foo/bar/* -> all pages below /foo/bar
# : /foo/bar[./]* -> all pages below and /foo/bar itself
# : *.html -> all .html files
/glob "*"
/type "allow"
}
/0001
{
# the globbing pattern to be compared against the url
# example: * -> everything
# : /foo/bar.* -> only the /foo/bar documents
# : /foo/bar/* -> all pages below /foo/bar
# : /foo/bar[./]* -> all pages below and /foo/bar itself
# : *.html -> all .html files
/glob "/en/news"
/type "allow"
}
/0002
{
# the globbing pattern to be compared against the url
# example: * -> everything
# : /foo/bar.* -> only the /foo/bar documents
# : /foo/bar/* -> all pages below /foo/bar
# : /foo/bar[./]* -> all pages below and /foo/bar itself
# : *.html -> all .html files
/glob "*/private/*"
/type "allow"
}
/0003
{
.....
}
....
}
# The invalidate section defines the pages that are "invalidated" after
# any activation. Please note that the activated page itself and all
# related documents are flushed on an modification. For example: if the
# page /foo/bar is activated, all /foo/bar.* files are removed from the
# cache.
/invalidate
{
/0000
{
/glob "*"
/type "deny"
}
/0001
{
# Consider all HTML files stale after an activation.
/glob "*.html"
/type "allow"
}
/0002
{
/glob "*.zip"
/type "allow"
}
/0003
{
/glob "*.pdf"
/type "allow"
}
}
# Each farm configures a set of load balanced renders (i.e. remote servers)
/farms
{
# First farm entry
/website
{
# Request headers that should be forwarded to the remote server.
/clientheaders
{
# Forward all request headers that are end-to-end. If you want
# to forward a specific set of headers, you'll have to list
# them here.
"*"
}
# Hostname globbing for farm selection (virtual domain addressing)
/virtualhosts
{
# Entries will be compared against the "Host" request header
# and an optional request URL prefix.
#
# Examples:
#
# www.company.com
# intranet.*
# myhost:8888/mysite
"*"
}
# The load will be balanced among these render instances
/renders
{
/rend01
{
# Hostname or IP of the render
/hostname "localhost"
# Port of the render
/port "4502"
# Connect timeout in milliseconds, 0 to wait indefinitely
# /timeout "0"
}
/rend02
{
/hostname "121.40.140.2"
/port "4502"
# /timeout "0"
}
/rend03
{
/hostname "121.40.140.2"
/port "4503"
/timeout "0"
}
}
# The filter section defines the requests that should be handled by the dispatcher.
# The globs will be compared against the request line, e.g. "GET /index.html HTTP/1.1".
/filter
{
# Deny everything first and then allow specific entries
/0001 { /type "deny" /glob "*" }
# Open consoles
# /0011 { /type "allow" /glob "* /admin/*" } # allow servlet engine admin
# /0012 { /type "allow" /glob "* /crx/*" } # allow content repository
# /0013 { /type "allow" /glob "* /system/*" } # allow OSGi console
# Allow non-public content directories
/0021 { /type "allow" /glob "* /apps/*" } # allow apps access
/0022 { /type "allow" /glob "* /bin/*" }
/0023 { /type "allow" /glob "* /content*" } # disable this rule to allow mapped content only
/0024 { /type "allow" /glob "* /libs/*" }
# /0025 { /type "deny" /glob "* /libs/shindig/proxy*" } # if you enable /libs close access to proxy
/0026 { /type "allow" /glob "* /home/*" }
/0027 { /type "allow" /glob "* /tmp/*" }
/0028 { /type "allow" /glob "* /var/*" }
# Enable specific mime types in non-public content directories
/0041 { /type "allow" /glob "* *.css *" } # enable css
/0042 { /type "allow" /glob "* *.gif *" } # enable gifs
/0043 { /type "allow" /glob "* *.ico *" } # enable icos
/0044 { /type "allow" /glob "* *.js *" } # enable javascript
/0045 { /type "allow" /glob "* *.png *" } # enable png
/0046 { /type "allow" /glob "* *.swf *" } # enable flash
/0047 { /type "allow" /glob "* *.jpg *" } # enable jpg
/0048 { /type "allow" /glob "* *.jpeg *" } # enable jpeg
# Enable features
/0062 { /type "allow" /glob "* /libs/cq/personalization/*" } # enable personalization
# Deny content grabbing
/0081 { /type "deny" /glob "GET *.infinity.json*" }
/0082 { /type "deny" /glob "GET *.tidy.json*" }
/0083 { /type "deny" /glob "GET *.sysview.xml*" }
/0084 { /type "deny" /glob "GET *.docview.json*" }
/0085 { /type "deny" /glob "GET *.docview.xml*" }
/0086 { /type "deny" /glob "GET *.*[0-9].json*" }
# /0087 { /type "allow" /glob "GET *.1.json*" } # allow one-level json requests
# Deny query
/0090 { /type "deny" /glob "* *.query.json*" }
}
# The cache section regulates what responses will be cached and where.
/cache
{
# The docroot must be equal to the document root of the webserver. The
# dispatcher will store files relative to this directory and subsequent
# requests may be "declined" by the dispatcher, allowing the webserver
# to deliver them just like static files.
# /docroot "<Apache_document_root>"
# /docroot "G:/aaa"
/docroot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"
# Sets the level upto which files named ".stat" will be created in the
# document root of the webserver. When an activation request for some
# page is received, only files within the same subtree are affected
# by the invalidation.
/statfileslevel "2"
# Flag indicating whether to cache responses to requests that contain
# authorization information.
/allowAuthorized "0"
# Flag indicating whether the dispatcher should serve stale content if
# no remote server is available.
#/serveStaleOnError "0"
# The rules section defines what responses should be cached based on
# the requested URL. Please note that only the following requests can
# lead to cacheable responses:
#
# - HTTP method is GET
# - URL has an extension
# - Request has no query string
# - Request has no "Authorization" header (unless allowAuthorized is 1)
/rules
{
/0000
{
# the globbing pattern to be compared against the url
# example: * -> everything
# : /foo/bar.* -> only the /foo/bar documents
# : /foo/bar/* -> all pages below /foo/bar
# : /foo/bar[./]* -> all pages below and /foo/bar itself
# : *.html -> all .html files
/glob "*"
/type "allow"
}
/0001
{
# the globbing pattern to be compared against the url
# example: * -> everything
# : /foo/bar.* -> only the /foo/bar documents
# : /foo/bar/* -> all pages below /foo/bar
# : /foo/bar[./]* -> all pages below and /foo/bar itself
# : *.html -> all .html files
/glob "/en/news"
/type "allow"
}
/0002
{
# the globbing pattern to be compared against the url
# example: * -> everything
# : /foo/bar.* -> only the /foo/bar documents
# : /foo/bar/* -> all pages below /foo/bar
# : /foo/bar[./]* -> all pages below and /foo/bar itself
# : *.html -> all .html files
/glob "*/private/*"
/type "allow"
}
/0003
{
# the globbing pattern to be compared against the url
# example: * -> everything
# : /foo/bar.* -> only the /foo/bar documents
# : /foo/bar/* -> all pages below /foo/bar
# : /foo/bar[./]* -> all pages below and /foo/bar itself
# : *.html -> all .html files
/glob "*/private/*"
/type "allow"
}
/0004
{
/glob "*/content/*"
/type "allow"
}
/0005
{
/glob "*/var/*"
/type "allow"
}
/0006
{
/glob "*/system/*"
/type "allow"
}
}
# The invalidate section defines the pages that are "invalidated" after
# any activation. Please note that the activated page itself and all
# related documents are flushed on an modification. For example: if the
# page /foo/bar is activated, all /foo/bar.* files are removed from the
# cache.
/invalidate
{
/0000
{
/glob "*"
/type "deny"
}
/0001
{
# Consider all HTML files stale after an activation.
/glob "*.html"
/type "allow"
}
/0002
{
/glob "*.zip"
/type "allow"
}
/0003
{
/glob "*.pdf"
/type "allow"
}
}
# The allowedClients section restricts the client IP addresses that are
# allowed to issue activation requests.
/allowedClients
{
# Uncomment the following to restrict activation requests to originate
# from "localhost" only.
#
#/0000
# {
# /glob "*"
# /type "deny"
# }
#/0001
# {
# /glob "127.0.0.1"
# /type "allow"
# }
}
# The ignoreUrlParams section contains query string parameter names that
# should be ignored when determining whether some request's output can be
# cached or delivered from cache.
#
# In this example configuration, the "q" parameter will be ignored.
/ignoreUrlParams
{
/0001 { /glob "*" /type "allow" }
/0002 { /glob "q" /type "allow" }
}
}
# The statistics sections dictates how the load should be balanced among the
# renders according to the media-type.
/statistics
{
/categories
{
/html
{
/glob "*.html"
}
/others
{
/glob "*"
}
}
}
}
}
此时就可以通过本机web服务器访问启动的instance上的一些页面了。
1. 虽然是为publish instance配制dispatcher,进行缓存,但配制是在author instance上的。
进入author instance的Tools
页面,切换至Replication
————->Agents on publish
—————->Dispatcher Flush
页面,重新拷贝一份,如图
2. 进入拷贝的Dispatcher Flush页面,点击Edit
进入设置页面, Settings
tab设置dispatcher Flush的名称Name
,描述Description
,设置启动开关Enabled
Transport
tab设置URI
,我本机apache为http://localhost:81/dispatcher/invalidate.cache
,点击OK
.
至此,window下dispatcher已经全部配置完成。
apache服务器安装时记得在httpd.conf文件内修改默认端口号Listener;
dispatcher.any配置时记得配置renders,设置ip和端口号port,用来指定扫描的instance