Advertisement:

Configure Lighttpd Simple vHost for Automatic Sub-Domain Handling

This document covers how to setup Lighty to automatically make folders in the document root named as sub-domains actual sub-domains. So that if in your document root (e.g. /var/www/htdocs) you have a folder named cool.yoursite.com (e.g. /var/www/htdocs/cool.yoursite.com)then Lighty will automatically direct requests for http://cool.yoursite.com to that folder.

Step One

Enable simple vhost in Lighty. In Debian this is as simple as:

 # lighttpd-enable-mod simple-vhost

Step Two

Add the following host setting in your Lighty config file:

 $HTTP["host"] !~ "^(notthis\.yoursite\.com|northis\yoursite\.com)$" {
  simple-vhost.server-root = "/var/www/htdocs" 
  simple-vhost.default-host = "www.yoursite.com" 
  simple-vhost.document-root = ""    
 }

Note that for this to work other host settings need to be removed since all sub-domains will be handled by the settings in this section unless they are configure as exceptions (see below). This does a few things:

 simple-vhost.server-root = "/var/www/htdocs" 

tells Lighty that all folders named something.yoursite.com in the document root /var/www/htdocs should be made into sub-domain sites. So if you download a flatfile CMS and name it flatcms.yoursite.com in /var/www/htdocs then Lighty will send all requests for flatcms.yoursite.com to that folder.

 simple-vhost.default-host = "www.yoursite.com"

tells Lighty that any sub-domain requests that do not correspond to a folder in the document root will be sent to the folder:

 /var/www/htdocs/www.yoursite.com

in the document root.

 $HTTP["host"] !~ "^(notthis\.yoursite\.com|northis\yoursite\.com)$"

is not only the begining for your host section but it tells Lighty that notthis.yoursite.com and northis.yoursite.com are exceptions and will have their own config sections that should look like this:

 #### notthis.yoursite.com ####
 #
  
 $HTTP["host"] == "notthis.yoursite.com" {
  server.document-root = "/var/www/htdocs/notthis.yoursite.com"
  accesslog.filename   = "/somewhere/logs/wwwlogs/notthis.yoursite.access.log"
  
 url.rewrite-once = (
 
 specific rewrite settings for example
 ) 
 
 }

That's It

And with that you have simple vHost set up in Lighty. You may add as many exceptions as you like to the first $HTTP[“host”] !~ line.

Advertisement:
lighty/simplevhost.txt · Last modified: 2012/02/16 02:33 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki Install DokuWiki