April 27, 2020
Estimated Post Reading Time ~

Enabling Multi Site supports in AEM through Dispatcher and publisher configurations

Multi-Site- Management in Adobe CQ V-5.6.1 and Apache Dispatcher V.2.2.15

This document will explain the approach to set up Multisite in Adobe CQ5. Site A - /content/sitea
Site B - /content/siteb
BIG-IP URLS - www.example1.com & www.example2.com

Mapping in publisher
Go to localhost:4503/system/console/configMgr with admin credentials.
Search for Apache Sling Resource Resolver, and change the value of mapping location from /etc/map to /etc/map.publish


Go to crx/de console,
Create a node /etc/map.publish of type sling:folder and under this node create an another node with
name http of type sling:OrderedFolder
Create a node of name www.example1.com of type sling:mapping and give the properties as below,
1. Name : Sling:internalRedirect Type : String[]
Value: /content/sitea
  
Create an another node under /etc/map.publish/httpd/www.example1.com/ as redirect of type sling : redirect and give the following properties.
1. Name : Sling: internalRedirect Type: String []
Value: /content/sitea/$1,/$1
2. Name : Sling: match Type: String
Value: (.+)$
Repeat the steps for www.example2.com

Creation of flush agents
Go to http://localhost:4503/miscadmin, click on replication, and double click on agents on publish.


Double click on Dispatcher flush agent and click on edit.
Give name, description as per your requirement, and click on the transport tab and give the value of URL as http://www.example1.com/dispatcher/invalidate.cache and go settings tab and check to enable the option.


Copy the flush agent and paste it in the same place and replace URL from http://www.example1.com/dispatcher/invalidate.cache to http://www.example2.com/dispatcher/invalidate.cache and check the enable option.

Configuring Apache dispatcherCache path for site1 is /app/apache/dispatcher/cache/site1
Cache Path for site2 is /app/apache/dispatcher/cache/site2
File owners and group for /app/apache is apache.
Default path for all configurations is at /etc/httpd/conf
Open httpd.conf file and enter the following content under Virtual host section,( It will be at the end of the file)

<VirtualHost *:80>
ServerName
www.example1.comDocumentRoot /app/apache/dispatcher/cache/site1 RewriteEngine on
RedirectMatch ^/$ /en.html
RewriteRule ^/content/sitea/(.*)$ /$1 [NE,L,R=301]

<Directory /app/apache/dispatcher/cache/site1/en> <IfModule disp_apache2.c>
SetHandler dispatcher-handler
ModMimeUsePathInfo On </IfModule>
Options FollowSymLinks AllowOverride None
</Directory> </VirtualHost>

<VirtualHost *:80>
ServerName
www.example2.comDocumentRoot /app/apache/dispatcher/cache/site2 RewriteEngine on
RedirectMatch ^/$ /en.html
RewriteRule ^/content/siteb/(.*)$ /$1 [NE,L,R=301]

<Directory /app/apache/dispatcher/cache/site2/en> <IfModule disp_apache2.c>
SetHandler dispatcher-handler
ModMimeUsePathInfo On </IfModule>
Options FollowSymLinks
AllowOverride None </Directory>
</VirtualHost>

Include dispatcher.any file as our configuration file in httpd.conf by adding the following after load module section,

<IfModule disp_apache2.c>
# location of the configuration file. eg: 'conf/dispatcher.any' DispatcherConfig conf/dispatcher.any
# location of the dispatcher log file. eg: 'logs/dispatcher.log'
#DispatcherLog /app/apache/logs/dispatcher.log
DispatcherLog '|/usr/sbin/rotatelogs /app/apache/logs/%Y-%m-%d-dispatcher.log
86400 -240'

# log level for the dispatcher log # 0 Errors
# 1 Warnings
# 2 Infos
# 3 Debug DispatcherLogLevel 0
# if turned to 1, the dispatcher looks like a normal module DispatcherNoServerHeader 0

# if turned to 1, request to / are not handled by the dispatcher 
# use the mod_alias then for the correct mapping DispatcherDeclineRoot 0

# if turned to 1, the dispatcher uses the URL already processed 
# by handlers preceding the dispatcher (i.e. mod_rewrite)
# instead of the original one passed to the webserver. DispatcherUseProcessedURL 0

# if turned to 1, the dispatcher does not spool an error
# response to the client (where the status code is greater 
# or equal than 400), but passes the status code to
# Apache, which e.g. allows an ErrorDocument directive 
# to process such a status code.
DispatcherPassError 0 
</IfModule>

Add the following in dispatcher.any file, 
/farms
    $include "farm1.any" $include "farm2.any"
}

Create a file renders.any under the path /etc/httpd/conf/ and add the following content:
/rend01 
{
# Hostname or IP of the render 
/hostname "localhost"
# Port of the render
/port "4503"
# Connect timeout in milliseconds, 0 to wait indefinitely 
# /timeout "0"
}

Create a file farm1.any and add the following content:
# 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 "www.example1.com" }
# The load will be balanced among these render instances
/renders {
$include "renders.any"
}
# The filter section defines the requests that should be handled by the dispatcher.
#
  • #  Entries can be either specified using globs, or elements of the request line: #
  • #  (1) globs will be compared against the entire request line, e.g.: #
  • #  /0001 { /type "deny" /glob "* /index.html *" } #
  • #  matches request "GET /index.html HTTP/1.1" but not "GET /index.html?a=b HTTP/1.1". #
  • #  (2) method/url/query/protocol will be compared againts the respective elements of
  • #  the request line, e.g.: #
  • #  /0001 { /type "deny" /method "GET" /url "/index.html" } #
  • #  matches both "GET /index.html" and "GET /index.html?a=b HTTP/1.1". #
  • #  Note: specifying elements of the request line is the preferred method. /filter
{
# Deny everything first and then allow specific entries /0001 { /type "allow" /glob "*" }
# # #
# #
# #
# # #
# Open consoles
/0011 { /type "allow" /url "/admin/*" } # allow servlet engine admin 
/0012 { /type "allow" /url "/crx/*" } # allow content repository 
/0013 { /type "allow" /url "/system/*" } # allow OSGi console
# Allow non-public content directories
/0021 { /type "allow" /url "/apps/*" } # allow apps access 
/0022 { /type "allow" /url "/bin/*" }
/0023 { /type "allow" /url "/content*" } # disable this rule to allow mapped content only
/0024 { /type "allow" /url "/libs/*" }
/0025 { /type "deny" /url "/libs/shindig/proxy*" } # if you enable /libs close access to proxy
/0026 { /type "allow" /url "/home/*" } 
/0027 { /type "allow" /url "/tmp/*" } 
/0028 { /type "allow" /url "/var/*" }
/0029 { /type "allow" /url "/services*" } # added for social media icon services
/0030 { /type "allow" /glob "* /en*" } # disable this rule to allow mapped content only
# Enable specific mime types in non-public content directories 
/0041 { /type "allow" /url "*.css" } # enable css
/0042 { /type "allow" /url "*.gif" } # enable gifs
/0043 { /type "allow" /url "*.ico" } # enable icos
/0044 { /type "allow" /url "*.js" } # enable javascript
/0045 { /type "allow" /url "*.png" 
} # enable png
/0046 { /type "allow" /url "*.swf" 
} # enable swf
/0047 { /type "allow" /url "*.jpg" } # enable jpg 
/0048 { /type "allow" /url "*.jpeg" } # enable jpeg 
/0049 { /type "allow" /url "*.svg" } # enable svg 
# Enable features
/0061 { /type "allow" /glob "POS /content/[.]*.form.html" } # under content /0062 { /type "allow" /url "/libs/cq/personalization/*" } # enable personalization
# Deny content grabbing
/0081 { /type "deny" /url "*.infinity.json" } /0082 { /type "deny" /url "*.tidy.json" } /0083 { /type "deny" /url "*.sysview.xml" } /0084 { /type "deny" /url "*.docview.json" } /0085 { /type "deny" /url "*.docview.xml" }
} # enable javascript } # enable png
} # enable flash
/0086 { /type "deny" /url "*.*[0-9].json" }
/0087 { /type "allow" /method "GET" /url "*.1.json" } # allow one-level json requests
#Deny crx and system console
/0088 { /type "deny" /url "/crx/de" }
/0089 { /type "deny" /url "/system/console*"} # Deny query
/0090 { /type "deny" /url "*.query.json" }
/0091 { /type "allow" /url "/training*" }
}
# 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 "/app/apache/dispatcher/cache/site1"
# 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 "0"
# 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
#
#
#
#
#
#
# /rules {
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)
/0000 {
/glob "*" /type "allow" }
/0001 {
/glob "/libs/cq/security/userinfo.json" /type "deny"
}
}
# 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 "/etc/segmentation.segment.js"
/type "allow"
} /0003
{
/glob "*/analytics.sitecatalyst.js" /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 "deny" }
    # /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 "*"
}
}

Create the file called farm2.any and add the same content as farm1.any and do the following changes: Change the www.example1.com to www.example2.com
/virtualhosts {
#
#
#
#
#
#
#
# "
www.example2.com" }
Entries will be compared against the "Host" request header and an optional request URL prefix.

Examples:
www.company.com intranet.* myhost:8888/mysite
Cache path should be changed to /docroot "/app/apache/dispatcher/cache/site1" should be changed to /docroot "/app/apache/dispatcher/cache/site2"



By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.