Project

General

Profile

HowToSupportConfigurationPerVirtualHost » History » Revision 5

Revision 4 (Evert, 2008-06-23 12:24) → Revision 5/6 (funkyhat, 2010-02-18 01:09)

h1. How to Support Configuration per Virtual Host 


 


 # Use mod_simple_vhost to set up your virtual hosts in subdirectories, e.g. `/www/servers/www.mydomain.com/` etc. 

 # Add an @include_shell@ option to the end of your config file: 


 


 <pre> 

 

 include_shell "/www/config_servers" 
 </pre> 


 


 # Create the file `/www/config_servers` with the following contents, and make sure it is readable (and executable?) by the lighttpd server: 


 


 <pre> 

 

 #!/bin/bash 

 for VHOST in `find /var/servers/ -mindepth 1 -maxdepth 1    \( -type d -or -type l \) -exec test -e "{}/server.conf" \; -exec basename "{}" \; 2>/dev/null` ; do { 
   echo "\$HTTP[\"host\"] == \"$VHOST\" {" 
   echo "var.vhost_name = \"$VHOST\"" 
   echo "server.document-root "var.vhost_path = \"/www/servers/$VHOST\"" 
   cat "/www/servers/$VHOST/server.conf" 
   echo "}" 
 } ; done 
 </pre> 


 


 Then for each virtual host, just create a @server.conf@ file containing the options that should pertain to that host;    the @config_servers@ script will wrap them in a condition matching the hostname, and set two variables: 

 * @vhost_name@ : the virtual host name, e.g. "www.mydomain.com" 
 * @vhost_path@ : the path to the virtual host directory, e.g. "/www/servers/www.mydomain.com"