Image may be NSFW.
Clik here to view.
Currently, most companies have multiple domains; they want to serve these domain requests from one single AEM instance, because of the obvious cost and management savings.
This article describes configuring multiple domains (/content/geometrixx-outdoors and /content/geometrixx-media) and their caching mechanisms in AEM.
The below configuration changes are validated in:
- Linux
- AEM 6.2 (no service packs or hot fixes)
- Apache 2.4 (Make sure you use the port number: 80. You can use any port you want, but you have to change the below config files)
- Dispatcher versions: 4.2.2
Set up the AEM Instances:
Install and configure the AEM author and publish instances. Please see the below link on how to install the AEM on your local environment:
https://docs.adobe.com/docs/en/aem/6-2/deploy.html#Default Local Install
Dispatcher Setup:
The process to setup a Dispatcher for your local environment is considerably easier than you think. If you need help, see the below documents:
- http://aempodcast.com/2017/infrastucture/week-aem-set-dispatcher-macos/#.WdZ8d1tSxaQ
- https://docs.adobe.com/docs/en/dispatcher/disp-install.html
Caching Location:
Let’s set up a separate caching locations for both the domains.
Create the below folders under /var/www/html:
geometrixx-outdoors
geometrixx-media
Make sure to give the full permissions to these folders so dispatcher can write the files to these folders.
sudo chmod -R 0644 /var/www/html/geometrixx-outdoors
sudo chmod -R 0644 /var/www/html/geometrixx-media
The idea is to place the geometrixx-outdoors website cache under: /var/www/html/ geometrixx-outdoors folder and geometrixx-media cache under: /var/www/html/ geometrixx-media.
Virtual Hosts:
When you have multiple domains, you need to create a separate dispatcher urls for each domain.
In this article, I am using the below url:
www.geometrix-outdoors.com to hit the geometrixx outdoors pages.
www.geometrix-media.com to hit the geometrixx media pages.
Default dispatcher setup will have only one virtual host. Let’s say you have two domains, then you need to create two separate virtual host files.
1. Create geometrixx-outdoors.conf file under: /etc/apache2/sites-enabled
2. Open the above file and paste the below content:
DocumentRoot "/var/www/html/geometrixx-outdoors" ServerName www.geometrix-outdoors.com ServerAlias geometrix-outdoors.com IncludeOptional /etc/apache2/conf/geometrixx-outdoors-redirects.conf ModMimeUsePathInfo On SetHandler dispatcher-handler Options FollowSymLinks AllowOverride None
geometrixx-outdoors-redirects.conf can have the url shortening configs, rewrites and redirects configurations.
You can include them in this virtual host also. You don’t need a separate file. However, it comes in handy in the maintenance if you fork this out.
3. Create geometrixx-media.conf file under: /etc/apache2/sites-enabled
4. Open the above file and paste the below content:
DocumentRoot "/var/www/html/geometrixx-media" ServerName www.geometrix-media.com ServerAlias geometrix-media.com IncludeOptional /etc/apache2/conf/geometrixx-media-redirects.conf ModMimeUsePathInfo On SetHandler dispatcher-handler Options FollowSymLinks AllowOverride None
geometrixx-media-redirects.conf can have the url shortening configs, rewrites and redirects configurations.
Make sure you are loading/including these two conf files in apache2.conf.
IncludeOptional /etc/apache2/ sites-enabled /geometrixx-outdoors.conf
IncludeOptional /etc/apache2/ sites-enabled /geometrixx-media.conf
Farm files setup:
It is important to set up the separate farm files for easy maintenance. You can have one single file for multiple domains. However, you can achieve the following goals if you have a separate farm file for each domain:
1. Restricting a specific path(s) in one domain while allowing access in the other domain
2. Enable caching for specific types of files in one domain, while denying caching in the other domain
3. Maintaining separate. stat file depth (/statfileslevel)
4. Enable ttl on one domain and disable on the other domain.
5. Maintain separate headers for each domain
6. Maintain separate vanity url file for each domain
I’ve listed only a few use cases to demonstrate the use of a separate farm file.
Create a separate farm file for geometrixx-outdoors and make sure you configure the correct virtual host. See below.
/virtualhosts { # Entries will be compared against the "Host" request header # and an optional request URL prefix. " www.geometrix-media.com" }
Create a separate farm file for geometrixx-outdoors and make sure you configure the correct virtual host. See below.
/virtualhosts { # Entries will be compared against the "Host" request header # and an optional request URL prefix. " www.geometrix-outdoors.com" }
Make sure to include these two farm files in your dispatcher.conf file.
Disabling the cross-domain access:
Users can access geometrixx-media pages from www.geometrix-outdoors.com and vice versa. To avoid this, you should throw an error page when user are trying to access another domain page. You can use RewriteCond to achieve this.
Add the below conditions to geometrixx-outdoors-redirects.conf file.
RewriteCond %{REQUEST_URI} ^/content/geometrixx-media RewriteCond %{REQUEST_URI} ^/content/dam/geometrixx-media RewriteRule .* [R=404,L,NC]
Add the below conditions to geometrixx-media-redirects.conf file.
RewriteCond %{REQUEST_URI} ^/content/geometrixx-outdoors RewriteCond %{REQUEST_URI} ^/content/dam/geometrixx-outdoors RewriteRule .* [R=404,L,NC]
Setting the dispatcher flush agents:
You should set up a separate flush agent for each domain. Below is the dispatcher flush agent configuration for geometrixx-outdoors.
1. Transport tab settings:
Image may be NSFW.
Clik here to view.
2. Make sure this agent has the below headers.
Image may be NSFW.
Clik here to view.
3. Trigger this agent whenever it receives the replication events:
Image may be NSFW.
Clik here to view.
Similarly, create a new dispatcher flush agent for geometrixx-media and follow steps 1-3. Make sure you change the URI.
Flushing Cache:
When authors replicate the geometrixx-outdoors page then it should touch the corresponding .stat files to invalidate the cache. Similarly, when authors replicate the geometrixx-media pages, it should invalidate the geometrixx-media pages.
To achieve this, make sure you have the below configuration in your apache2.conf file:
# Geometrixx-outdoors Domain SetEnvIfNoCase CQ-Path ".*/content/geometrixx-outdoors/.*" FLUSH_HOST=www. geometrixx-outdoors.com RequestHeader set Host %{FLUSH_HOST}e env=FLUSH_HOST SetEnvIfNoCase CQ-Path ".*/content/dam/ geometrixx-outdoors /.*" FLUSH_HOST=www. geometrixx-outdoors.com RequestHeader set Host %{FLUSH_HOST}e env=FLUSH_HOST # Geometrixx-media Domain SetEnvIfNoCase CQ-Path ".*/content/geometrixx-media/.*" FLUSH_HOST=www. geometrixx-media.com RequestHeader set Host %{FLUSH_HOST}e env=FLUSH_HOST SetEnvIfNoCase CQ-Path ".*/content/dam/geometrixx-media/.*" FLUSH_HOST=www. geometrixx-media.com RequestHeader set Host %{FLUSH_HOST}e env=FLUSH_HOST
In the above config, its reading the header values set in the dispatcher flush agents and determining the host.
Modify the host file:
You need to modify your local host file to test these changes. You need to add the below entries to your host file:
127.0.0.1 www.geometrixx-outdoors.com
127.0.0.1 www.geometrixx-media.com
Restart the apache and test your changes.
References:
http://www.cognifide.com/our-blogs/cq/multidomain-cq-mappings-and-apache-configuration/
https://www.netcentric.biz/blog/aem-dispatcher-cache-invalidation-for-multiple-dispatcher-farms.html
Image may be NSFW.
Clik here to view.Author bio
Singaiah Chintalapudi is a Senior Developer who has worked on a multitude of AEM implementations. He has been working with AEM since 2012 and is heavily involved in designing and developing numerous AEM projects. His interests include performance optimization, security, scalability, and third-party integrations with AEM.