mod_vhost

mod_vhost offers various ways to implement virtual webhosts

It can map hostnames to actions and offers multiple ways to do so.
These ways differ in the flexibility of mapping (what to map and what to map to) as well as performance.

vhost.map (action)

maps given hostnames to action blocks

vhost.map mapping;
mapping
key-value list with hostnames as keys and actions as values

vhost.map offers a fast (lookup through hash-table) and flexible mapping, but maps only exact hostnames (no pattern/regex matching). The server port is never considered part of the hostname. Use the key default (keyword, not as string) to specify a default action.

Example

vhost.map ["host1" => actionblock1, "host2" => actionblock2, ..., "hostN" => actionblockN, default => actionblock0];

vhost.map_regex (action)

maps matching hostname patterns to action blocks

vhost.map_regex mapping;
mapping
key-value list with regular expressions for hostnames as keys and actions as values

vhost.map_regex walks through the list in the given order and stops at the first match; if no regular expression matched it will use the default action (if specified).

Example

vhost.map_regex ["host1regex" => actionblock1, "host2regex" => actionblock2, ..., "hostNregex" => actionblockN, default => actionblock0];

vhost.debug (option)

enable debug output

vhost.debug value;
Default value: false

Example

Combining both actions is also possible.

What it does (for example):

  • if example.com or www.example.com is requested, the block named “examplesite” will be executed
  • if mydomain.tld is requested, the block named “mydomain” will be executed
  • if mydomain.com or www.mydomain.net is requested, the block named “mydomain” will be executed (through the regex matching)
  • if www.mydomain.tld or something entirely different is requested, the block named “defaultdom” will be executed
setup {
	module_load "mod_vhost";
}

examplesite = {
	#... more config here ...
};

mydomain = {
	#... more config here ...
};

defaultdom = {
	#... more config here ...
};

vhost.map [
	"example.com" => examplesite,
	"www.example.com" => examplesite,
	"mydomain.tld" => mydomain,
	default => {
		vhost.map_regex [
			"^(www\.)?mydomain\.(com|net|org)$" => mydomain,
			default => defaultdom
		];
	}
];