When you host multiple web sites on one server, you may find that most of them have similar configuration. To add a new virtual host, you have to duplicate existing configuration and then just make some minor changes. Also if you need to change one common configuration, you have to edit all the configuration files one by one. It is annoying and error-prone. LiteSpeed provides this excellent feature: virtual host template, which will reduce the burden of a web master in above situations.
For example, if all web sites are stored on a hard drive like below:
NOTE: web site root directories do not have to be the same as the domain name, it is just a example shows that how to configure a virtual host with just one configuration parameter.
The virtual host template should be configured like below:
“Virtual host root” should be set to “/wwwroot/$VH_NAME/”
“Document Root” should be set to “$VH_ROOT/html/” or “/wwwroot/$VH_NAME/html/”, the former is preferred.
To add a “CGI
” context, set “URI
” to “/cgi-bin/”, set “Path” to “$VH_ROOT/cgi-bin/” or “/wwwroot/$VH_NAME/cgi-bin”, the former is preferred.
If all web sites are available on port 80, you can create a listener bind to all interfaces on port 80 and add the name of that listener to “Mapped Listeners” configuration.
Then the rest you need to do is to configure a member virtual host for each web site. Properties for a member virtual host are:
Virtual Host Name: This probably the only property need to be set if all other parameters is based on virtual host name. (like naming the directory after it, and the domain name is same as the virtual host name).
Domain: need to be set when the qualified domain name of the web site is different from “Virtual Host Name”.
Aliases: need to be set if there are aliases for this web site.
Virtual Host Root: The root directory for a web site, only need to be set when it cannot be determined by “Virtual Host Name”.
For “www.example.com“, because “Virtual Host Name” is equal to “Domain” and the virtual host root directory is named after “Virtual Host Name”, and there is no alias, so all you need to do is to set “Virtual Host Name” to “www.example.com“. If you organize all your new virtual hosts in this way, then all you need to do is to add a member virtual host with a proper “Virtual host name”.
In real-world setup, like server managed by cPanel, the “Virtual Host Root” is not based on “Virtual host name”, you need to specify the actual virtual host root directory for a template member.
If you need to customize some configruation for a virtual host, you can click “Instaniate” link to create a dedicate vhost configuration and customize it there.