Project

General

Profile

Enhanced Virtual-Hosting

Module: mod_evhost

Description

mod_evhost builds the document-root based on a pattern which contains
wildcards. Those wildcards can represent parts of the submitted hostname

  %% => % sign
  %0 => domain name + tld
  %1 => tld
  %2 => domain name without tld
  %3 => subdomain 1 name
  %4 => subdomain 2 name
  %_ => full domain name
  %{M.N} => single character at 1-indexed position N in the domain segment %M (e.g %0 - %9) (since 1.4.43)
evhost.path-pattern = "/home/www/servers/%3/pages/"

Note that % patterns in evhost.path-pattern have the special meanings listed above. They do not have the same meanings as % substitutions in url.redirect and url.rewrite-*.

Options

evhost.path-pattern
pattern with wildcards to be replace to build a documentroot

Samples

User vhosts

  $HTTP["host"] =~ "users\.example\.org" {
      evhost.path-pattern = "/home/%4/public_html/" 
  }

http://johndoe.users.example.org/ => /home/johndoe/public_html/

Since lighttpd 1.4.43:

  $HTTP["host"] =~ "users\.example\.org" {
      evhost.path-pattern = "/home/%{4.1}/%4/public_html/" 
  }

http://johndoe.users.example.org/ => /home/j/johndoe/public_html/

General Example

  server.document-root = "/home/user/sites/default/site" 
  evhost.path-pattern  = "/home/user/sites/%0/site/" 

If example.org is requested, and /home/user/sites/example.org/site/ is found, that path becomes the docroot.

If example.net is requested but no directory named /home/user/sites/example.net/site/ exists, then the docroot remains /home/user/sites/default/site

A Bad Example

  server.document-root = "/home/user/sites/" 
  evhost.path-pattern  = "/home/user/sites/%0/site/" 

server.document-root should never point to the directory with your evhost subdirs.
Here's why: Assume foo.example.com and bar.example.com both point to the server.
Assume that /home/user/sites/foo.example.com/site exists, but /home/user/sites/bar.example.com/site does not.

If foo.example.com is configured via mod_auth:

  $HTTP["host"] == "foo.example.com" {
    auth.require = ( "/" => ...
    ) 
  }

We could bypass the configured auth by accessing http://bar.example.com/foo.example.com/site/