diff options
author | Andy Carlson <ace@ibook-debian> | 2017-01-12 12:45:53 -0500 |
---|---|---|
committer | Andy Carlson <ace@ibook-debian> | 2017-01-12 12:45:53 -0500 |
commit | deaed1e4b09af0340f7a590bd0067eb6864db771 (patch) | |
tree | 0f09dcbf173e16454263da48ed39ea1b8e28274f | |
parent | ec1547ef8a002d71031d70d12f5fbfdc791e9c1f (diff) |
initial commit
-rw-r--r-- | Makefile | 10 | ||||
-rw-r--r-- | README.md | 18 | ||||
-rw-r--r-- | config.sh | 18 | ||||
-rw-r--r-- | dispatcher-sites.conf.m4 | 8 | ||||
-rw-r--r-- | dispatcher.conf.m4 | 182 | ||||
-rw-r--r-- | init.sh | 20 | ||||
-rw-r--r-- | redirect.conf | 13 |
7 files changed, 267 insertions, 2 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2f6ef7d --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +all: + mkdir build + mkdir tmp + . ./init.sh + . ./config.sh + cp redirects.conf build + +clean: + rm -rf build + rm -rf tmp @@ -1,2 +1,16 @@ -# apache-aem-dispatcher -Configure Apache for use as an AEM Dispatcher +# aem-dispatcher-config + +This generates configuration files for Apache Web Server to be able function as an Adobe Experience Manager (AEM) Dispatcher. You will need to load the dispatcher module and manage the ```dispatcher.any``` file on your own, however this will allow you to easily configure multiple sites serve them through Apache. + +### Configuration: +1. Run ```make``` +2. Enter the server DNS names/folder. + a. Note that the folder should exist under /content + b. When you're done enter nothing for server and folder to continue +3. Enter the server name that your dispatcher will be accessed with +4. Enter the path to your SSL cert/key files for dispatcher + +### Installation: +1. Copy files into place on the filesystem: + a. ##-dispatcher*.conf - <APACHE>/conf.d + b. redirects.conf - <APACHE>/conf diff --git a/config.sh b/config.sh new file mode 100644 index 0000000..ef3f4de --- /dev/null +++ b/config.sh @@ -0,0 +1,18 @@ +printf "Configuring dispatcher and macros..." +CERTPATH=$(cat ./tmp/settings.txt | grep '^CERT' | sed 's/^CERT //g') +KEYPATH=$(cat ./tmp/settings.txt | grep '^KEY' | sed 's/^KEY //g') +WWWROOT=$(cat ./tmp/settings.txt | grep '^ROOT' | sed 's/^ROOT //g') +SVRNAME=$(cat ./tmp/settings.txt | grep '^SVR' | sed 's/^SVR //g') +(printf "define(\`HTTPREWRITE',\`" ; cat ./tmp/domainlisting.txt | sed 's/^/ Use RewriteSiteHTML http /g' ; printf "')\n") > ./tmp/dispatcher.m4 +(printf "define(\`HTTPSREWRITE',\`" ; cat ./tmp/domainlisting.txt | sed 's/^/ Use RewriteSiteHTML https /g' ; printf "')\n") >> ./tmp/dispatcher.m4 +printf "define(\`CERTPATH',\`$CERTPATH')\n" >> ./tmp/dispatcher.m4 +printf "define(\`KEYPATH',\`$KEYPATH')\n" >> ./tmp/dispatcher.m4 +printf "define(\`DOCROOT',\` DocumentRoot $WWWROOT')\n" >> ./tmp/dispatcher.m4 +printf "define(\`SERVERDNSNAME',\`$SVRNAME')\n" >> ./tmp/dispatcher.m4 +cat ./tmp/dispatcher.m4 dispatcher.conf.m4 | m4 > build/dispatcher.conf +printf "done\n" + +printf "Configuring sites..." +(printf "define(\`SITEDEFS',\`" ; cat ./tmp/domainlisting.txt | sed 's/^/Use AemSite /g' ; printf "')\n" ) > ./tmp/dispatcher-sites.m4 +cat ./tmp/dispatcher-sites.m4 dispatcher-sites.conf.m4 | m4 > build/dispatcher-sites.conf +printf "done\n" diff --git a/dispatcher-sites.conf.m4 b/dispatcher-sites.conf.m4 new file mode 100644 index 0000000..66a6ef9 --- /dev/null +++ b/dispatcher-sites.conf.m4 @@ -0,0 +1,8 @@ +Use AemDirectory /mnt/data/wwwroot/apps +Use AemDirectory /mnt/data/wwwroot/bin +Use AemDirectory /mnt/data/wwwroot/content +Use AemDirectory /mnt/data/wwwroot/etc +Use AemDirectory /mnt/data/wwwroot/libs +Use AemDirectory /mnt/data/wwwroot/system + +SITEDEFS diff --git a/dispatcher.conf.m4 b/dispatcher.conf.m4 new file mode 100644 index 0000000..773fc61 --- /dev/null +++ b/dispatcher.conf.m4 @@ -0,0 +1,182 @@ +<IfModule disp_apache2.c> + DispatcherConfig conf/dispatcher.any + DispatcherLog logs/dispatcher.log + DispatcherLogLevel 3 + DispatcherNoServerHeader 0 + DispatcherDeclineRoot 0 + DispatcherUseProcessedURL 0 + DispatcherPassError 0 +# DispatcherKeepAliveTimeout 60 +</IfModule> + +<Macro RewriteSiteHTML $proto $domain $sitename> + Substitute "s|/content/$sitename.html|/|in" + Substitute "s|/content/$sitename|$proto://$domain|in" +</Macro> + +<Macro ExclusiveRewrite $prefix $url $target> + RewriteCond "%{REQUEST_URI}" "$prefix$url(.*)$" + RewriteRule ^(.*)$ $target [R] +</Macro> + +<VirtualHost *:80> + ServerName SERVERDNSNAME +DOCROOT + + RewriteEngine on + + Include conf/redirects.conf + + <LocationMatch ".(html|js)$"> + SetOutputFilter SUBSTITUTE + + # Use RewriteSiteHTML http +HTTPREWRITE + </LocationMatch> + + <Directory /> + <IfModule disp_apache2.c> + SetHandler dispatcher-handler + </IfModule> + Options FollowSymLinks + AllowOverride None + </Directory> + <Location /dispatcher> + <IfModule disp_apache2.c> + SetHandler dispatcher-handler + </IfModule> + Options FollowSymLinks + AllowOverride None + Require all granted + </Location> +</VirtualHost> + +<VirtualHost *:443> + ServerName SERVERDNSNAME +DOCROOT + + SSLEngine on + SSLCertificateFile CERTFILEPATH + SSLCertificateKeyFile KEYFILEPATH + + RewriteEngine on + + Include conf/redirects.conf + + <LocationMatch ".(html|js)$"> + SetOutputFilter SUBSTITUTE + + # Use RewriteSiteHTML https +HTTPSREWRITE + </LocationMatch> + + <Directory /> + <IfModule disp_apache2.c> + SetHandler dispatcher-handler + </IfModule> + Options FollowSymLinks + AllowOverride None + </Directory> + <Location /dispatcher> + <IfModule disp_apache2.c> + SetHandler dispatcher-handler + </IfModule> + Options FollowSymLinks + AllowOverride None + Require all granted + </Location> +</VirtualHost> + +<Macro AemDirectory $dirpath> + <Directory $dirpath> + Require all granted + </Directory> +</Macro> + +<Macro AemGlobalPath $proto $path> + <Location $path> + ProxyPass $proto://SERVERDNSNAME$path + ProxyPassReverse $proto://SERVERDNSNAME$path + </Location> +</Macro> + +<Macro AemSite $domain $contentfolder> + <VirtualHost *:80> + ServerName $domain + + ProxyRequests Off + RewriteEngine On + + RewriteCond "%{REQUEST_URI}" "^/.html$" + RewriteRule "^(.*)$" "http://$domain/" [R] + + RewriteCond "%{REQUEST_URI}" "^/$" + RewriteRule "^(.*)$" "http://SERVERDNSNAME/content/$contentfolder.html" [P] + + RewriteCond "%{REQUEST_URI}" ".+/$" + RewriteRule "^/(.*)/$" "http://$domain/$1.html" [R] + + RewriteCond "%{REQUEST_URI}" !\.[a-zA-Z0-9]*$ + RewriteCond "%{REQUEST_URI}" !^/content/dam + RewriteRule "^/(.*)[/]*$" "http://$domain/$1.html" [R] + + RewriteCond "%{REQUEST_URI}" "^/.+/.html$" + RewriteRule "^/(.*)/.html$" "http://$domain/$1" [R] + + Header edit Location "^http://dispatcher.localhost/(.*)$" "http://$domain/$1" + + Use AemGlobalPath http /apps + Use AemGlobalPath http /bin + Use AemGlobalPath http /etc + Use AemGlobalPath http /libs + Use AemGlobalPath http /system + Use AemGlobalPath http /content/dam + + ProxyPass / http://SERVERDNSNAME/content/$contentfolder/ + ProxyPassReverse / http://SERVERDNSNAME/content/$contentfolder/ + </VirtualHost> + + <VirtualHost "*:443"> + ServerName $domain + + SSLEngine on + SSLProxyEngine on + SSLCertificateFile CERTPATH + SSLCertificateKeyFile KEYPATH + + ProxyRequests Off + RewriteEngine On + + RewriteCond "%{REQUEST_URI}" "^/.html$" + RewriteRule "^(.*)$" "https://$domain/" [R] + + RewriteCond "%{REQUEST_URI}" "^/$" + RewriteRule "^(.*)$" "https://SERVERDNSNAME/content/$contentfolder.html" [P] + + RewriteCond "%{REQUEST_URI}" ".+/$" + RewriteRule "^/(.*)/$" "https://$domain/$1.html" [R] + + + RewriteCond "%{REQUEST_URI}" !\.[a-zA-Z0-9]*$ + RewriteCond "%{REQUEST_URI}" !^/content/dam + RewriteRule "^/(.*)[/]*$" "https://$domain/$1.html" [R] + + RewriteCond "%{REQUEST_URI}" "^/.+/.html$" + RewriteRule "^/(.*)/.html$" "https://$domain/$1" [R] + + Header edit Location "^https://dispatcher.localhost/(.*)$" "https://$domain/$1" + + Use AemGlobalPath https /apps + Use AemGlobalPath https /bin + Use AemGlobalPath https /etc + Use AemGlobalPath https /libs + Use AemGlobalPath https /system + Use AemGlobalPath https /content/dam + + SSLProxyCheckPeerExpire off + SSLProxyCheckPeerName off + SSLProxyCheckPeerCN off + ProxyPass / https://SERVERDNSNAME/content/$contentfolder/ + ProxyPassReverse / https://SERVERDNSNAME/content/$contentfolder/ + </VirtualHost> +</Macro> @@ -0,0 +1,20 @@ +echo "Press <enter> when you're done entering domain/nodes" +domcount="1" +while true; do + read -p "($domcount) Enter domain: " thisdomain + read -p "($domcount) Enter node (/content/FOLDERNAME): " thisfolder + if [ -z "$thisdomain" ] || [ -z "$thisfolder" ]; then + break + fi + printf "$thisdomain $thisfolder\n" >> tmp/domainlisting.txt + export domcount=$[ $domcount + 1 ] +done + +read -p "Enter webroot: " wwwroot +read -p "Enter server name: " servername +read -p "Enter SSL certificate path: " thiscertpath +read -p "Enter SSL key path: " thiskeypath +echo "ROOT $wwwroot" > tmp/settings.txt +echo "SVR $servername" >> tmp/settings.txt +echo "CERT $thiscertpath" >> tmp/settings.txt +echo "KEY $thiskeypath" >> tmp/settings.txt diff --git a/redirect.conf b/redirect.conf new file mode 100644 index 0000000..c999b68 --- /dev/null +++ b/redirect.conf @@ -0,0 +1,13 @@ +########################################### +# Usage: +# Use ExclusiveRewrite <site-root> <folder-path> <target-url> +# +# site-root - /content/<site> +# folder-path - path within site-root (/section/page.html) +# target-url - URL to redirect to +# +# Example: +# Use ExclusiveRewrite /content/mysite /people/joe.html http://www.joe.com +# +########################################## + |