Вы находитесь на странице: 1из 7

Apache Server Side Includes (SSI) in AEM pages

What is SSI
SSI (Server Side Includes) are directives that are placed in HTML pages, and evaluated on the server while the
pages are being served. They let you add dynamically generated content to an existing HTML page, without having
to serve the entire page via dynamic technology such as JSP.
How does SSI works
In Apache HTTP server, SSI module (mod_include) need to be loaded and enabled for the server to perform SSI.
SSI is purely Apache concept and has nothing to do with the underlying Dynamic technology used for e.g. in case
AEM it has nothing to with dispatcher or publish server. Dispatcher is the Adobe recommended way to cache html
page response for performance reasons.
In order to direct Apache server to include a dynamic content on server side the html page uses the following
include directive
<!--#include virtual="<path of html fragment to be included>" -->
e.g.
<!--#include virtual="/content/geometrixx/en/_jcr_content/par/datetest.nocache.html" --></div>
When the server encounters the above tag in HTML page it tries to include the html fragment from the mentioned
path relative to server document root. If the file is not found there, Apache requests the underlying Application server
for the file and creates the file at the path mentioned in include tag. If the file is not found in Application server then
Apache creates zero byte file.
Apache Configuration to enable SSI
1. Make sure that the following module in enabled/loaded in Apache config file (httpd.conf)
LoadModule include_module modules/mod_include.so

1. Add includes option in directory config element. This tells apache to permit files to be parsed for SSI directive
<Directory "c:/work/install/Apache22/htdocs">
Options Indexes FollowSymLinks MultiViews Includes
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
AddHandler server-parsed .html
AddHandler server-parsed .htm
AllowOverride None
Order allow,deny
Allow from all

</Directory>

Integrating Apache with AEM


The following block diagram shows the AEM and Apache/Dispatcher configuration
In the local environment, Author is running on port 4502, Publish on 4503, Apache defaults to port 80

Configure dispatcher module in apache with its render pointed to AEM publish instance.
Dispatcher can be loaded and configured in apache as follows

LoadModule dispatcher_module modules/disp_apache2.2.dll


<IfModule disp_apache2.c>
DispatcherConfig conf/dispatcher.any
DispatcherLog

logs/dispatcher.log

DispatcherLogLevel 3
DispatcherNoServerHeader 0
DispatcherDeclineRoot 0
DispatcherUseProcessedURL 0
DispatcherPassError 0
</IfModule>

<Directory />
<IfModule disp_apache2.c>
ModMimeUsePathInfo On
SetHandler dispatcher-handler

</IfModule>
SetOutputFilter INCLUDES
Options FollowSymLinks Includes
AllowOverride None
In the dispacther config file, configure the rendered to point to Publish instance.
/renders
{
/rend01
{
# Hostname or IP of the render
/hostname "127.0.0.1"
# Port of the render
/port "4503"
# Connect timeout in milliseconds, 0 to wait indefinitely
# /timeout "0"
}
}
Demonstrating AEM component fragment SSI inclusion

Above component is rendered as

2. SSI include the component on some other page where you want to display the same component.

3. Publish both the pages and check the page output for both pages on publish.

The page where we added the actual component will show component content

The other page we added the SSI include directive will not show the component content.

Now try and hit this same page with SSI directive via Apache/Dispatcher using the following url
http://localhost/content/geometrixx/en/products.html

This page will show the component content included using SSI directive.

Also check the Apache directory at the path mentioned in the SSI directive. You should notice a html file created
over there

Now next step is to change the component content in author on the page you placed the actual component
and publish it.
Changed the Name to "Deepak" and published the page.

On the publish server I can see that the page has changed. The Page where we SSI component doesn't show the
content if we hot it directly.

Now hit the Products page (Where we SSI component) via Apache. You should see the updated content i.e. the
name changed to "Deepak" even though we actually haven't published the Products page.

Conclusion: The above tests demonstrates the Use Case where we have a common component that may be
displayed on multiple pages of the website, common example is header/footer, which is being authored and
published once and the changes get reflected on all the pages where it is being used without actually publishing all
the pages. Including common component Via SSI allows for improved performance in publishing content (obviously
as less content is published).