Wednesday, March 13, 2013

How to manage multi site using dispatcher in CQ / WEM

Use Case:

1) You have multi language site and you want to have different dispatcher configuration for them
2) Activating pages under english site should not flush pages under french site for example
3) I have different URL for each site (for example en.mysite.com and fr.mysite.com)

Solution:

At Publish Instance

First of all, In order to manage multi domain multi language site, You should have proper mapping rule within CQ. Please see http://dev.day.com/content/kb/home/cq5/CQ5SystemAdministration/HowToMapDomains.html for that

Now what this is going to do is, make sure that your links are properly written when you open any page under different domain.

Example of sample /etc/map

map
  +-- http
    +-- any_geometrixx.de (nodetyp: sling:Mapping)
        property: internalRedirect : /content/geometrixx/de.html
        property: sling:match : .*.*geometrixx.de.(4503|80)+/$
    +-- libs (nodetyp: sling:Mapping)
          property: internalRedirect: /libs
      +-- etc (nodetyp: sling:Mapping)
        +-- designs (nodetyp: sling:Mapping)
            property: internalRedirect: /etc/designs
    +-- any_geometrixx.en (nodetyp: sling:Mapping)
        property: internalRedireect: /content/geometrixx/en.html
        property: sling:match : .*.*geometrixx.en.(4503|80)+/$
      +-- libs (nodetyp: sling:Mapping)
          property: internalRedirect: /libs
      +-- etc (nodetyp: sling:Mapping)
        +-- designs (nodetyp: sling:Mapping)
            property: internalRedirect: /etc/designs


At Dispatcher

First of all you have to associate dispatcher handler with each incoming domain. You can use Name Virtual Host for this

better to create different farm for different domain

# Each farm configures a set of load balanced renders (i.e. remote servers)
/farms
  {
       $include farm*.any
  }

Suppose you have two farms,

farm_site1.any
farm_site2.any

Then you will have virtual host setting as,

 /virtualhosts
      {
 
      "*site1*"
      }

 /renders
      {
       $include "renders.any"
      }

/cache
   /docroot "<Global Doc root>/site1"

And

/virtualhosts
      {
 
      "*site2*"
      }


    /renders
      {
       $include "renders.any"
      }

  /cache
    /docroot "<Global Doc root>/site2"

You can have same or different renderers for different site.

Now at your virtual host setting you will configure different doc root for different site

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName site1.com
    #This is to handle dev enviornments
    ServerAlias *.site1.com
    DocumentRoot <Global Doc root>/site1
    Include <Configurations specific to site1>
 
</VirtualHost>

<VirtualHost *:80>
    ServerName site2.com
    #This is to handle dev enviornments
    ServerAlias *.site2.com
    DocumentRoot <Global Doc root>/site2
    Include <Configurations specific to site2>
 
</VirtualHost>
DocumentRoot <Global Doc root>

Now to handle dispatcher flush request for specific site path, You can have rule like,


SetEnvIfNoCase CQ-Path ^/content/site1 hostnameforfarm=site1.com
SetEnvIfNoCase CQ-Path ^/content/site2 hostnameforfarm=site2.com
RequestHeader set Host %{hostnameforfarm}e env= hostnameforfarm

Now above rule will set the host name for dispatcher based on {CQ-Path} in flush request. That mean if some thing under site1 get activated site2 cache will NOT be flushed.

I know there could be many variation to this, I just gave basic example. Let me know if you have more questions.

6 comments:

  1. Hi,

    what do you mean by hostnameforfarm ? Isn't it the same as main domain ?

    ReplyDelete
    Replies
    1. No. It could be any thing. for example to have separate host name to manager dam something like dam.yoursite.com or manage micro site, for example something.othersite.com. All dispatcher farm cares about it host name.

      Delete
  2. I tried something like this below. but I don't think apache accepts them.... The configuration needs to tested I guess so
    SetEnvIfNoCase CQ-Path ^/content/mysite/test hostnameforfarm=mysite.com
    SetEnvIfNoCase CQ-Path ^/content/mysite1 hostnameforfarm=mysite1.com
    RequestHeader set Host %{hostnameforfarm}e env= hostnameforfarm

    ReplyDelete
    Replies
    1. Saravanan,

      Apache should accept that. I think you need to have http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html

      Yogesh

      Delete
  3. Greetings. I'm interested in knowing why you have implemented the apache "setEnvIfNoCase" directives so the correct sites are flushed. I would have assumed CQ would take care of this.
    Or is it something doesn't do well?

    ReplyDelete
    Replies
    1. If you are using multidomain caching then Dispatcher will not know which flush to clear. Then in that case you would need setEnvIfNoCase to set correct host. Let me know if that make sense.

      Delete