Apache 2 virtual host
A very easy example
config file:
<VirtualHost *:80>
ServerAlias www.example.org
ServerAdmin webmaster@example.org
ServerSignature On
CustomLog /var/log/apache2/example.org-access.log combined
ErrorLog /var/log/apache2/example.org-error.log
LogLevel warn
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^/(.*) \
http://localhost:10080/VirtualHostBase/http/%{SERVER_NAME}:80/example_org/VirtualHostRoot/$1 [L,P]
</IfModule>
</VirtualHost>
A virtual host serving zope
www.example.org.conf:
<VirtualHost *:80>
ServerAlias www.example.org
ServerAdmin webmaster@example.org
ServerSignature On
# we don't need a DocumentRoot for a zope only sites
#DocumentRoot /var/www/example.org
CustomLog /var/log/apache2/example.org-access.log combined
ErrorLog /var/log/apache2/example.org-error.log
LogLevel warn
# log the deflate compression rate to a file
#CustomLog /var/log/apache2/deflate_log deflate
<IfModule mod_rewrite.c>
RewriteEngine On
# use RewriteLog to debug problems with your rewrite rules
# disable it after you found the error our your harddisk will be filled *very fast*
# RewriteLog "/var/log/apache2/rewrite_log"
# RewriteLogLevel 2
# serving icons from apache 2 server
RewriteRule ^/icons/ - [L]
# rewrite any access to manage to a secure server
RewriteRule ^/(.*)/manage(.*) \
https://secure.example.org/zope/example_instance/example_org/$1/manage$2 [NC,R=301,L]
RewriteRule ^/manage(.*) \
https://secure.example.org/zope/example_instance/example_org/manage$1 [NC,R=301,L]
# rewrite any other access to the zope server using a proxy [P] and add the VMH magic keywords
# use %{SERVER_NAME} instead of example.com to avoid busting the ServerAlias
# %{HTTP_HOST} is bad because it may contain the port
RewriteRule ^/(.*) \
http://localhost:10080/VirtualHostBase/http/%{SERVER_NAME}:80/example_org/VirtualHostRoot/$1 [L,P]
</IfModule>
<IfModule mod_proxy.c>
ProxyVia On
# prevent the webserver from beeing used as proxy
<LocationMatch "^[^/]">
Deny from all
</LocationMatch>
</IfModule>
# caching (disabled)
# this caches every file with the correct caching informations starting at /
<IfModule mod_disk_cache.c>
#CacheEnable disk /
</IfModule>
# compression (disabled)
<IfModule mod_deflate.c>
#SetOutputFilter DEFLATE
</IfModule>
</VirtualHost>
Additional rewrite rules
Rewrite rules used for serving the secure manage access.
HTTP host redirecting every access to the https server:
<VirtualHost *:80> ServerName secure.example.org ServerAdmin webmaster@example.org ServerSignature On # we don't need a DocumentRoot for zope only sites #DocumentRoot /var/www/secure.example.org CustomLog /var/log/apache2/secure.example.org-access.log combined ErrorLog /var/log/apache2/secure.example.org-error.log LogLevel warn <IfModule mod_rewrite.c> RewriteEngine On # use RewriteLog to debug problems with your rewrite rules # disable it after you found the error our your harddisk will be filled *very fast* # RewriteLog "/var/log/apache2/rewrite_log" # RewriteLogLevel 2 # Rewrite with redirect moved permanently RewriteRule ^/(.*) https://secure.example.org/$1 [R=301, L] </IfModule> </VirtualHost>
SSL Host serving all manage access to zope:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName secure.example.org
ServerAdmin webmaster@example.org
ServerSignature On
DocumentRoot /var/www/secure.example.org-ssl
CustomLog /var/log/apache2/secure.example.org-ssl-access.log combined
ErrorLog /var/log/apache2/secure.example.org-ssl-error.log
LogLevel warn
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/crt/secure.example.org.crt
SSLCertificateKeyFile /etc/apache2/ssl/key/secure.example.org.key
<Location />
# Force usage of ssl encryption
SSLRequireSSL
# SSL client certs: none, optional, require
# Note: optional doesn't work with all browsers
SSLVerifyClient optional
SSLVerifyDepth 1
SSLOptions +StdEnvVars +StrictRequire
#optional +ExportCertData
</Location>
<IfModule mod_rewrite.c>
RewriteEngine On
# use RewriteLog to debug problems with your rewrite rules
# disable it after you found the error our your harddisk will be filled *very fast*
# RewriteLog "/var/log/apache2/rewrite_log"
# RewriteLogLevel 2
# The following rules will rewrite any access to https://secure.example.org/zope/example_instance/
# to the root of the zope instance running at localhost:10080
RewriteRule ^/zope/main_instance$ \
http://localhost:10080/VirtualHostBase/https/secure.example.org:443/VirtualHostRoot/_vh_zope/_vh_example_instance [L,P]
RewriteRule ^/zope/main_instance/(.*) \
http://localhost:10080/VirtualHostBase/https/secure.example.org:443/VirtualHostRoot/_vh_zope/_vh_example_instance/$1 [L,P]
</IfModule>
<IfModule mod_proxy.c>
ProxyVia On
# prevent the webserver from beeing used as proxy
<LocationMatch "^[^/]">
Deny from all
</LocationMatch>
</IfModule>
# don't try to cache ssl!
# compression (disabled)
<IfModule mod_deflate.c>
#SetOutputFilter DEFLATE
</IfModule>
</VirtualHost>
</IfModule>