Showing posts with label AEM dispatcher on windows. Show all posts
Showing posts with label AEM dispatcher on windows. Show all posts

Friday, October 1, 2021

AEM Dispatcher Setup Using Docker - Windows

 


Dispatcher Setup


The AEM as a Cloud Service SDK includes the recommended Dispatcher Tools version, that facilitates configuring, validating, and simulating Dispatcher locally. Dispatcher Tools is comprised of:

  • a baseline set of Apache HTTP Web server and Dispatcher configuration files, located in .../dispatcher-sdk-x.x.x/src
  • a configuration validator CLI tool, located at .../dispatcher-sdk-x.x.x/bin/validate (Dispatcher SDK 2.0.29+)
  • a configuration generation CLI tool, located at .../dispatcher-sdk-x.x.x/bin/validator
  • a configuration deployment CLI tool, located at .../dispatcher-sdk-x.x.x/bin/docker_run
  • a Docker image that runs Apache HTTP Web server with the Dispatcher module

Prerequisites:

  1. Windows users must use Windows 10 Professional.
  2. Install Experience Manager Publish Quickstart Jar on the local develop machine. Please refer local set-up.
  3. Install and start the latest version of Docker (Docker Desktop 2.2.0.5+ / Docker Engine v19.03.9+) on the local development machine.

Dispatcher Set-Up

 Dispatcher tools comes along with aem-sdk. Extract this zip file.

 

 



 

In the extracted folder, there is aem-sdk-dispacther-tools-x.x.xx-windows.zip. Extract this zip in some folder, you can see below structure.

 

 



src folder contains below folders:

 


Configuration Structure:

 

./

── conf.d

   ── available_vhosts

      └── default.vhost

   ── dispatcher_vhost.conf

   ── enabled_vhosts

      ── README

      └── default.vhost -> ../available_vhosts/default.vhost

   └── rewrites

      ── default_rewrite.rules

      └── rewrite.rules

   └── variables

|       ── custom.vars

       └── global.vars

└── conf.dispatcher.d

    ── available_farms

       └── default.farm

    ── cache

       ── default_invalidate.any

       ── default_rules.any

       └── rules.any

    ── clientheaders

       ── clientheaders.any

       └── default_clientheaders.any

    ── dispatcher.any

    ── enabled_farms

       ── README

       └── default.farm -> ../available_farms/default.farm

    ── filters

       ── default_filters.any

       └── filters.any

    ── renders

       └── default_renders.any

    └── virtualhosts

        ── default_virtualhosts.any

        └── virtualhosts.any

 

 

docs folder:

 


bin folder:

 



The bin subdirectory also contains a docker image and a shell script to execute that will use your deployment information and run an Apache and dispatcher in a docker container. It also contains a validator binary for macOS and Linux.

 

 

Local development and testing

Start publish instance and docker desktop first.

 

Step 1: Validate the Dispatcher configuration contained in this SDK

On Windows, go to dispatcher folder and run below command

> bin\validator full -d out src
 


This validates the configuration and generates deployment information in out.

Out folder is created in folder:

 



Step 2: Validate the deployment information by the Dispatcher in a docker image.

Run below command:

bin\docker_run out host.docker.internal:4503 8080

 

host.docker.internal is pointing to localhost.

 



 

Open any page in publish instance:

index page



Open same url on port 8080 as we started docker on this port 8080.




 


Dispatcher is working and we can access our publish instance pages on dispatcher.

Project Dispatcher’s code testing:

Step-1: Delete out folder from dispatcher’s folder.



Step-2: Now run below command to deploy project’s specific dispatcher configurations:

Let's add one rule in rewrite file.

rewrite.rules

custom.var file



bin\validator full -d out <loctaion>/dispatcher/src

 



out folder is created in the same folder:

 



 

Open any file to check your configurations. Let’s say I opened file “rewrite_rules” and you can see project specific configs are deployed successfully.

 



Step-3: Run below command

bin\docker_run out host.docker.internal:4503 8080

With your AEM publish server running on your system, listening on port 4503, you can start the dispatcher in front of that server as follows:



In rewrite file there is rule

RewriteRule ^/?$ /content/${CONTENT_FOLDER_NAME}/us/en.html [PT,L]

Now open browser and run http://localhost:8080/

dispatcher index page


 


Dispatcher is setup now.

Wednesday, June 3, 2020

Dispatcher Set up in AEM on Windows


Set up Dispatcher in AEM on Windows


In this tutorial, i am going to take you through how to set up a dispatcher in AEM on windows.

What is Dispatcher?


Dispatcher is Adobe Experience Manager's caching and/or load balancing tool. Dispatcher also helps to protect your AEM server from attack.

The Dispatcher helps realize an environment i.e. both fast and dynamic. It works as a part of a static HTML server, with the aim of:

  • Storing as much of the site content as is possible, in the form of a static website.
  • Accessing the layout as little as possible.
You need an Apache server to run Dispatcher. So first we need to set up the Apache server then we will add configuration of the dispatcher.

 

Install Apache Webserver on Windows:

Download Apache server from the trusted Apache site. Follow below link:

 http://archive.apache.org/dist/httpd/binaries/win32/

A lot of new versions are available for Apache. I am using apache server 2.2.  Follow the below steps to set up on windows:

Step 1: Download httpd-2.2.25-win32-x86-no_ssl.msi


Apache server page


Step 2Double click the downloaded msi file and click next and finish



By default, it will install at C:\Program Files (x86)\Apache Software Foundation\Apache2.2


Apache location 


Step 3: Go to your httpd.conf file C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf


·       Change default Define SRVROOT or ServerRoot path to absolute path of your apache2.2 folder “ C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf” (Line – 38).


·      Update listen port Listen 8080 (Line – 47), it is optional if you don’t want to change you can keep default port as 80.

 

·       Update ServerName localhost:8080 (Line – 173), it is optional if you don’t want to change you can keep default port as 80.

 

·       Now Go to the bin folder (C:\Program Files (x86)\Apache Software Foundation\Apache2.2\bin) and open command prompt.


·       run httpd -k start to start the server.


#Common Issue while starting the server

If it says the port is already bound to 80 port on 0.0.0.1:80 then change port in httpd.conf file.

Then change the port. Let’s say I am changing to port 81. Change port at line #47 and save it.

Step 4: Run httpd -k start command to start the apache server.

Check error.log in the logs folder of C:\Program Files (x86)\Apache Software 

Foundation\Apache2.2\logs.

If no error then opens a browser and type localhost. It shows it works!

You can change this content. For this:

  • Go to C:\Program Files(x86)\ApacheSoftwareFoundation\Apache2.2\htdocs
  • Open Index.html file.

        

  • Save this file and refresh the browser. You can see Updated content.
        
Step 5:  Now set up dispatcher on apache server.

 You just need to follow below steps:-

·       Download dispatcher build

·       Modify Apache web server httpd.conf file

·       Modify dispatcher.any file

·       Restart Apache web server and you are done.

 Download dispatcher build:

Go to below link:

https://www.adobeaemcloud.com/content/companies/public/adobe/dispatcher/dispatcher.html


Download the selected file. I am selecting no ssl.

Unzip dispatcher-apache2.2-windows-x86-4.2.3.zip file

Note# Its better to use the same version for both dispatcher and apache. I am using 2.2 for both. if you are working with 2.4 apache and 2.2 dispatcher then you might face some issue.

It contains below files:

§  disp_apache2.2.dll – This is my dispatcher module file, which we will     plugin with web server.

 

§  dispatcher.any – It is our dispatcher configuration file.


§  author_dispatcher.any – Sample file for configuring our dispatcher.


§  httpd.conf.disp2.conf – sample file to configure apache webserver.

 Now follow the below steps to configure dispatcher:

  • Go to C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf location where you have installed your apache server.
  •  Open httpd.conf file.
  •  Go to path where you have unzipped dispatcher. 
  • Open httpd.conf.disp2 file.
  •  Go to line #234
  •  Copy LoadModule dispatcher_module  modules/mod_dispatcher.so and paste anywhere in httpd.conf file 

    I am pasting line #130 where my load modules are ending.

 Change module "mod_dispacther.so" to modules/disp_apache2.2.dll as   dispatcher has .dll file.

 

Note:-This setting is used by apache webserver to load my dispatcher when next time Apache web server is started

Copy line #236-248 from httpd.conf.disp2.conf  file and paste it to httpd.conf file after ending of </IfModule>.

Below are the lines, you can use it directly.


<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    logs/dispatcher.log

   

    # log level for the dispatcher log, can be either specified

    # as a string or an integer (in parentheses)

    # error(0): Errors

    # warn(1):  Warnings

    # info(2):  Infos

    # debug(3): Debug

    # trace(4): Trace

    DispatcherLogLevel warn

   

    # if turned on, the dispatcher looks like a normal module

    DispatcherNoServerHeader Off

   

    # if turned on, request to / are not handled by the dispatcher

    # use the mod_alias then for the correct mapping

    DispatcherDeclineRoot Off

   

    # if turned on, the dispatcher uses the URL already processed

    # by handlers preceeding the dispatcher (i.e. mod_rewrite)

    # instead of the original one passed to the web server.

    DispatcherUseProcessedURL Off

   

    # 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.

    #

    # Additionally, one can specify the status code ranges that should

    # be left to web server to handle, e.g.

    #

    # DispatcherPassError 400-404,501

    DispatcherPassError 0

 

    #

    # DispatcherKeepAliveTimeout specifies the number of seconds a

    # connection to a backend should be kept alive. If not set or

    # set to zero, connections are not kept alive.

    #

    #DispatcherKeepAliveTimeout 60

 

</IfModule>

It contains below entries:

·          DispatcherConfig – location of the configuration file

·          DispatcherLog– location of the dispatcher log file

·          DispatcherPassError – to use your dispatcher for handling errors, if set to 1 then webserver will handle errors.

·         DispatcherKeepAliveTimeout – Time interval for which your request should be kept alive.

Now copy the dispatcher handler from httpd.conf.disp2.conf (line #370) to httpd.conf file(line #238). this will override the default handle of web server and allow the dispatcher to entertain all incoming requests. 

Add below code:

 <Directory />

 <IfModule disp_apache2.c>

 ModMimeUsePathInfo On

 # enable dispatcher for ALL request. if this is too restrictive,

 # move it to another location

 SetHandler dispatcher-handler

 </IfModule>

 Options FollowSymLinks

 AllowOverride None

</Directory>

 It might present in your httpd.conf. If it is there, then ignore the above step.

 

      Copy this disp_apache2.2.dll  file from downloaded dispatcher and paste it under C:\Program Files (x86)\Apache Software Foundation\Apache2.2\modules.

 

   Copy dispatcher.any file from downloaded dispatcher and paste it under C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf directory.

 Now open dispatcher.any file.

  • Change the port number in line 38. If you are setting up dispatcher for publish instance then use 4503 (default port of publish) or add your publish port here if not 4503.
  •  If you want to set up for author then set it 4502.

 


 

  • Then go to line #77
  •  Allow all paths for the author. Instead of denying, I am allowing this for testing purposes.



§     For Publish the instance you should deny all request and allow specific, For an author instance you should allow all and deny specific.

     Then go to /cache section.


§  Update cache Doc Root. It should exactly match my httpd.conf Documentroot path. Copy Document root path from httpd.conf file and paste it in dispatcher.any file at line 132.

 


§  Save all settings and Restart your Apache Web server.

httpd -k start

 

Test Dispatcher Installation:-


To test whether the dispatcher is configured properly or not. Check logs in your directory. You will find dispacther.log in the logs folder

 


Now open localhost:81 to your browser.

 

 

 

  

You will see, AEM instance is working on apache. I set up for the author. You can set port 4503 to publish.

Check http://localhost:81/editor.html/content/we-retail/us/en.html is working for you.

 

 

Congratulations!!!  Your dispatcher is set up now.

 If you want to add rewrite rules and test then follow below steps:

  • Add below lines just before end of this <IfModule disp_apache2.c> tag in httpd.conf file.

        RewriteEngine on

        RewriteRule ^/$ /content/we-retail.html [R]

  •  And uncomment line 119 which is:

         LoadModule rewrite_module modules/mod_rewrite.so

 Now Stop and restart your apache server.

 Type localhost:81 to your browser.




 It will redirect to we retail page. Because we set up a rule for we-retail page

RewriteRule ^/$ /content/we-retail.html [R] while setting up rules. So when you 

hit loclahost:81 then it will automatically go to http://localhost:81/content/we-

retail.html

 


Congratulations!!! Your rules also working now👍

 

 

 

 

 

 

 

 

 


Install yarn on windows

 In this article, we will see how we can install yarn on windows. First lets understand what yarn is? Yarn is an established open-source pac...