Dispatcher – еще одна часть AEM, предназначенная для кеширования и в качестве балансировщика нагрузки.
Является отдельным модулем, имеются версии для Apache HTTP 2.2, 2.4, MS IIS и других серверов.
В данном примере установка будет выполняться на Vagrant + Ubuntu 14.04 + Apache 2.2.
Содержание
Подготовка
Создаем каталог для Vagrant-бокса:
$ mkdir ~/VMs/Vagrant/AEM_Dispatcher $ cd ~/VMs/Vagrant/AEM_Dispatcher
Инициализируем Vagrantfile
:
$ vagrant init ubuntu/trusty64
Устанавливаем память и порты:
... config.vm.network "forwarded_port", guest: 80, host: 8080 ... config.vm.provider "virtualbox" do |vb| vb.memory = "2048" end ...
Запускаем и подключаемся:
$ vagrant up&& vagrant ssh
Устанавливаем Apache HTTP:
# apt-get update && apt-get -y install apache2
Проверяем:
# apache2 -v Server version: Apache/2.4.7 (Ubuntu) Server built: Oct 14 2015 14:20:21
# service apache2 status * apache2 is running
# curl localhost; echo $? ... 0
Установка Dispatcher
Загружаем подходящий архив отсюда>>>:
# cd /tmp/ # wget https://www.adobeaemcloud.com/content/companies/public/adobe/dispatcher/dispatcher/_jcr_content/top/download_10/file.res/dispatcher-apache2.4-linux-x86-64-4.1.11.tar.gz
Распаковываем:
# tar xfp dispatcher-apache2.4-linux-x86-64-4.1.11.tar.gz
# ls -l total 920 drwxr-xr-x 2 501 games 4096 Oct 15 09:51 conf -rwxr-xr-x 1 501 games 644021 Oct 22 15:38 dispatcher-apache2.4-4.1.11.so -rw-r--r-- 1 root root 275378 Nov 3 18:42 dispatcher-apache2.4-linux-x86-64-4.1.11.tar.gz -rw-r--r-- 1 501 games 3827 Oct 6 11:47 license.txt -rw-r--r-- 1 501 games 7357 Oct 22 15:19 release-notes.txt
Тут же есть готовые примеры файлов конфигурации:
# ls -l conf/ total 68 -rw-r--r-- 1 501 games 6314 Oct 6 11:47 README.dispatcher.apache2 -rw-r--r-- 1 501 games 6649 Oct 6 11:47 author_dispatcher.any -rw-r--r-- 1 501 games 9420 Oct 15 09:51 dispatcher.any -rw-r--r-- 1 501 games 37488 Oct 6 11:47 httpd.conf.disp2
Файл dispatcher-apache2.4-4.1.11.so
– разделяемая библиотека, которую добавляем в Apache:
# cp dispatcher-apache2.4-4.1.11.so /usr/lib/apache2/modules
Создаем каталог (или укажите свой путь в параметре DispatcherConfig
, до него дойдем позже):
# mkdir /etc/apache2/conf
Копируем файл конфигурации:
# cp conf/dispatcher.any /etc/apache2/conf
Добавляем файл /etc/apache2/mods-enabled/dispatcher.load
:
LoadModule dispatcher_module /usr/lib/apache2/modules/mod_dispatcher.so
Проверяем:
# apachectl -t ... Syntax OK
Добавляем в /etc/apache2/mods-enabled/dispatcher.load
настройки Dispatcher:
<IfModule disp_apache2.c> DispatcherConfig conf/dispatcher.any DispatcherLog /var/logs/dispatcher.log DispatcherLogLevel 3 DispatcherNoServerHeader 0 DispatcherDeclineRoot 0 DispatcherUseProcessedURL 0 DispatcherPassError 0 </IfModule>
Редактируем файл /etc/apache2/sites-enabled/000-default.conf
в котором описывает обработчик dispatcher-handler
для виртуалхоста:
<VirtualHost *:80> DocumentRoot /var/www/aemcache ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/aemcache> <IfModule disp_apache2.c> SetHandler dispatcher-handler ModMimeUsePathInfo On </IfModule> AllowOverride None </Directory> </VirtualHost>
Создаем директорию:
# mkdir /var/www/aemcache && chown www-data:www-data /var/www/aemcache
Перезагружаем Apache:
# service apache2 restart * Restarting web server apache2
# service apache2 status * apache2 is running
Готово.
Далее остается настроить RewriteRule
-ы.
Пример конфига с боевого сервера:
<VirtualHost *:80> <ifModule mod_rewrite.c> RewriteEngine on RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301] </ifModule> </VirtualHost> <VirtualHost *:443> <IfModule mod_ssl.c> SSLEngine on SSLProtocol all -SSLv2 SSLCertificateFile /etc/ssl/certs/host.crt SSLCertificateKeyFile /etc/ssl/private/host.key SSLCertificateChainFile /etc/ssl/certs/rootCA.crt </IfModule> DocumentRoot /data/dispatcher <Directory /data/dispatcher> Options FollowSymLinks AllowOverride None Order allow,deny Allow from all AddType text/html .html Header add "X-XSS-Protection" "1; mode=block" Header add "X-Content-Type-Options" "nosniff" Header add "Cache-control" "no-store" <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/javascript </IfModule> </Directory> <Directory /> <IfModule disp_apache2.c> ModMimeUsePathInfo On SetHandler dispatcher-handler </IfModule> Options FollowSymLinks AllowOverride None </Directory> <Location /server-status> SetHandler server-status Order Deny,Allow Deny from all Allow from 127.0.0.1 </Location> <Location /error> SetHandler None </Location> Alias /error /usr/share/apache2/error <ifModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|POST) RewriteRule .* - [R=405,L] RewriteRule ^/error/(.*) /error/$1 [PT,L] RewriteRule ^/etc - [PT] RewriteRule ^/libs - [PT] RewriteRule ^/content/dam - [PT] RewriteRule ^/sitemap.xml$ /content/projname/en/home.sitemap.xml [PT,L] RewriteRule ^/content/projname/en/home.html$ /home.html [R=301,L] RewriteRule ^/content/projname/en/results.html$ /results.html [R=301,L] RewriteRule ^/content/projname/en/categories/(.*) /$1 [R=301,L] RewriteRule ^/content/projname/en/answers/(.*) /faq/$1 [R=301,L] RewriteRule ^/content/projname/en/contacts/individual/(.*) /content/projname/en/home.html [R=301,L] RewriteRule ^/content/projname/en/contacts/groups/(.*) /content/projname/en/home.html [R=301,L] RewriteRule ^/content/projname/en/legal/(.*) /content/projname/en/home.html [R=301,L] RewriteRule ^/content/projname/en/promos/(.*) /content/projname/en/home.html [R=301,L] RewriteRule ^/faq/(.*) /content/projname/en/answers/$1 [PT,L] RewriteRule ^/about-you/(.*) /content/projname/en/categories/about-you/$1 [PT,L] RewriteRule ^/redirect-404-for-contact-us(.*) /contact-us.html [R=301,L] RewriteRule ^/contact-us.html /content/projname/en/contact-us.html [PT,L] RewriteRule ^/contact-us/(.*) /content/projname/en/contact-us/$1 [PT,L] RewriteRule ^/products/(.*) /content/projname/en/categories/products/$1 [PT,L] RewriteRule ^/bank-accounts/(.*) /content/projname/en/categories/bank-accounts/$1 [PT,L] RewriteRule ^/ways-to-bank/(.*) /content/projname/en/categories/ways-to-bank/$1 [PT,L] RewriteRule ^/$ /content/projname/en/home.html [R=301,L] RewriteRule ^/content/projname/en/(.*) - [PT] RewriteRule ^/(.+)$ /content/projname/en/$1 [PT,L] </ifModule> <IfModule mod_expires.c> ExpiresActive on ExpiresDefault "access plus 1 month" # CSS ExpiresByType text/css "access plus 4 hours" # JavaScript ExpiresByType application/javascript "access plus 4 hours" ExpiresByType application/x-javascript "access plus 4 hours" ExpiresByType text/javascript "access plus 4 hours" # Media files ExpiresByType audio/ogg "access plus 1 week" ExpiresByType image/bmp "access plus 1 week" ExpiresByType image/gif "access plus 1 week" ExpiresByType image/jpeg "access plus 1 week" ExpiresByType image/png "access plus 1 week" ExpiresByType image/svg+xml "access plus 1 week" ExpiresByType image/webp "access plus 1 week" ExpiresByType video/mp4 "access plus 1 week" ExpiresByType video/ogg "access plus 1 week" ExpiresByType video/webm "access plus 1 week" # Web fonts # Embedded OpenType (EOT) ExpiresByType application/vnd.ms-fontobject "access plus 4 hours" ExpiresByType font/eot "access plus 4 hours" # OpenType ExpiresByType font/opentype "access plus 4 hours" # TrueType ExpiresByType application/x-font-ttf "access plus 4 hours" # Web Open Font Format (WOFF) 1.0 ExpiresByType application/font-woff "access plus 4 hours" ExpiresByType application/x-font-woff "access plus 4 hours" ExpiresByType font/woff "access plus 4 hours" # Web Open Font Format (WOFF) 2.0 ExpiresByType application/font-woff2 "access plus 4 hours" </IfModule> LogLevel info ErrorLog /var/log/apache2/dispatcher-error.log CustomLog /var/log/apache2/dispatcher-access.log combined DispatcherPassError 404,500 ErrorDocument 404 /error/404.html ErrorDocument 500 /error/500.html <Location /content/projname/en/contact-us> ErrorDocument 404 /redirect-404-for-contact-us </Location> </VirtualHost>