When I have multiple virtual hosts with separate AEM Dispatcher cache farms configured in my web server, then how do I flush the correct cache from AEM?


Apache HTTP Server / AEM dispatcher


There are multiple solutions:

  1. Set up one dispatcher flush agent per dispatcher farm, set the Host header and configure the "Agent user ID" with a user that has read access to relevant paths.
  2. Configure the web server to set the correct Host header when certain paths are received in a flush request's CQ-Path header. 

In the solutions below we assume the following:

  • You are using Apache HTTP Server 2.2 or later version
  • Multiple VirtualHosts configured
  • Multiple dispatcher farms with separate caches

For example:
Apache httpd VirtualHost configurations:

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName www.geometrixx.com
    ServerAlias *.geometrixx.com
    DocumentRoot /var/www/html/cache-www-geometrixx-com

<VirtualHost *:80>
    ServerName www.geometrixx-outdoors.com
    ServerAlias *.geometrixx-outdoors.com
    DocumentRoot <Global Doc root>/site2
    Include <Configurations specific to site2>
DocumentRoot /var/www/html/cache-www-geometrixx-outdoors-com

In the dispatcher configuration, you have multiple farms configured to handle different sites by host name (virtualhosts):



  /cache {
       /docroot "/var/www/html/cache-www-geometrixx-com"

Solution 1: Set up multiple flush agents

If you only have a handful of separate dispatcher farms (5 or less), then configuring multiple flush agents is an easy solution.

  1. Open http://aem-host:port/miscadmin for each AEM publish instance

  2. Browse to Replication => Agents on Publish

  3. Click Edit

  4. Under the Agent user ID, enter the name for a user which you create later that would be associated with this agent.  You could use a naming convention with the host name of the site.  For example: "flush-agent-www-geometrixx-com" 

  5. Select the "Extended" tab

  6. Under HTTP Headers add another header.  As the value enter "Host: www.geometrixx.com" where "www.geometrixx.com" should be replaced by one of the sites' DNS hosts.

  7. Click Ok to save

  8. Go to http://aem-host:port/useradmin and create the user from step 4

  9. On the Permissions tab of the user, grant the user read access to any paths that you would like the agent to be allowed to flush for the referenced site.  For example: /content/geometrixx,  /content/dam, /etc, /libs, /apps, /var

  10. Save

  11. Repeat steps 1 - 10 for all other sites on each publish instance.  You will be creating one flush agent for each site on each publish instance.

  12. On the web server, share common paths using symlinks.  For example, you could set symlinks for /content/dam, /etc, /libs, /apps, and /var to a common cache location.  Then /content and anything under the root of the cache would be separately cached.  Here's an example command for the /libs folder 

    ln -s /var/www/html/cache-www-geometrixx-com/libs /var/www/html/shared-cache

  13. Now when you activate pages under a specific site, the flush request would only get directed to the applicable flush agent

Solution 2: Modify the Host header at the Web Server

To handle dispatcher flush requests for specific site paths, use rules like these in each :

SetEnvIfNoCase CQ-Path ^/content/geometrixx hostnameforfarm=www.geometrixx.com
SetEnvIfNoCase CQ-Path ^/content/geometrixx-outdoors hostnameforfarm=www.geometrixx-outdoors.com 
RequestHeader set Host %{hostnameforfarm}e env=hostnameforfarm

For this solution, you also need either symlinks or a shared dispatcher farm for shared content paths such as /content/dam, /etc, /libs, /apps, and /var.  See step 12 in Solution 1 above for details around using symlinks.