Search code examples
apachewebserveraemdispatchervhosts

How to setup multiple domains on AEM dispatcher


I have a website which is already hosted and using AEM. I have another domain which needs to be hosted. If it is hosted, what are the configurations that need to be configured on the same AEM system(Author, Publisher and Dispatcher).


Solution

  • The official Adobe documentation has already been provided to you in previous posts but it doesn't come close to covering everything that is required to achieve a proper multi-tenant setup.

    Unfortunately, multi-tenancy is something that can be quite difficult to get right if it hasn't been thought about right from the start and requires a highly competent team.

    Web Server

    Depending on your web server configuration, you will most likely have to add an additional VirtualHost entry for your new domain.

    <VirtualHost *:80>
        ServerName sitea.com
        DocumentRoot /usr/lib/apache/htdocs/content/sitea
        <Directory /usr/lib/apache/htdocs/content/sitea>
            <IfModule disp_apache2.c>
                SetHandler dispatcher-handler
                ModMimeUsePathInfo On
            </IfModule>
            Options FollowSymLinks
            AllowOverride None
        </Directory>
    </VirtualHost>
    

    If you are rewriting requests at the web server level, you will have to add new rewrite rules by configuring mod_rewrite accordingly so that requests are forwarded to the correct content path.

    Dispatcher

    In the dispatcher configuration, you will have to create a new farm for your site based on the virtual host. I suggest you break those up into files like so:

    /farms
    {
       $include "farm-sitea.any"
       $include "farm-siteb.any"
       $include "farm-flush.any"
    }
    

    Note: Make sure that users cannot access restricted content of another site using your new site. For example, if http://sitea.com/secure/page.html should not be accessible, make sure the same goes for http://siteb.com/secure/page.html.

    AEM

    If you are leveraging Sling Mappings for resolving requests coming in to your AEM instance, you will have to add additional entries for your new domain under /etc/map.

    I've written extensively on the topic of link rewriting here.

    Now that you are hosting multiple sites in a single AEM instance, you will need a common code base between the two applications to store instance-wide configuration and utility classes. Service configuration that you could include in this common package are:

    • com.day.cq.commons.servlets.RootMappingServlet.xml
    • com.day.cq.rewriter.linkchecker.impl.LinkCheckerImpl.xml
    • com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl.xml
    • org.apache.sling.servlets.resolver.SlingServletResolver.xml
    • com.day.cq.commons.impl.ExternalizerImpl.xml
    • etc

    When it comes to multi-tenancy, there is a LOT to think about. Some additional areas that you may need to cover are:

    • tagging taxonomy (centrally defined namespaces for content tagging)
    • ACLs (site A authors should be able to author site B)
    • internationalization
    • workflows (OOTB workflows will impact all sites)
    • DAM
    • etc

    Hope this helps!