When you host multiple web sites on one server, you may find that many of them have similar configurations. With LiteSpeed's virtual host template feature, you can create many virtual hosts from one master template and edit all their configurations at once.
Virtual host template settings are located in the Virtual Host Templates tab in the WebAdmin console (one of the main tabs under configuration).
By default, LSWS comes with three virtual host templates for three common types of virtual hosts:
We have made other custom templates that you can import into LSWS. Importation instructions are included in each template's guide, though all you have to do is copy the template (an XML file) into
$SERVER_ROOT/conf/templates/ and then add a template that is directed to the XML file in the WebAdmin console.
To create a brand new template, go to WebAdmin console > Configuration > Virtual Host Templates > Add. You will be asked to fill out basic information for this template. One of the fields will require the location of your template file. If you do not have a template file yet, that is OK. Make up a new file name (located in
$SERVER_ROOT/conf/templates/) and you will be given the option to have LSWS create the template file.
After adding your template, you do not have to set any more settings. You will most certainly want to, though. Otherwise, what would be the point of making a template?
Most of the settings in a virtual host template are comparable to normal virtual host settings. However, if you look around the default templates, you will notice a special variable,
$VH_NAME stands for the names of member virtual hosts you will add later. This allows you to create settings that are specific to each member virtual host. For example, the Default Virtual Host Root setting (under the General tab), requires that the default virtual host root path have the value
$VH_NAME. This is so that different member vhosts will have different roots depending on their name. (This is further pursued in the example below.)
The template is just that: a template. By itself it has no virtual hosts or websites. When you are ready to add virtual hosts with the templates settings, you must add member virtual hosts (WebAdmin console > Configuration > Virtual Host Templates > your template > Template > Member Virtual Hosts > Add). These member virtual hosts will have all the settings of your virtual host template. Anywhere that
$VH_NAME appears in the template settings the virtual host name of the particular member virtual host will be used.
The Instantiate link (available on the table of member vhosts under the Template tab) changes a member virtual host into a regular virtual host. This cuts the connection between this vhost and the template. Further changes in the template will not affect this vhost and changes can be made to this virtual host without affecting other virtual hosts. Instantiating allows you to create vhosts with the basic settings of the template, but with customized settings above and beyond the template settings. You can view and edit your instantiated vhosts in the Virtual Hosts tab (WebAdmin console > Configuration > Virtual Hosts).
As an example we will be creating a member vhost named “test” in the centralConfigLog template.
First I go to the template centralConfigLog in WebAdmin console > Configuration > Virtual Host Template.
Looking at the General settings (the General tab) I can see places where the name I choose for my member vhost will come into play.
I start to add a new member virtual host by going to the Template tab and clicking Add on the Member Virtual Hosts table.
I name my virtual host “test”. This will affect where files for this vhost should be put. Remembering the General settings, this new vhost will now have its virtual host root at
$SERVER_ROOT/test. Its config file will be
$SERVER_ROOT/conf/test. It's access log (not pictured above) will be
$SERVER_ROOT/logs/test.access.log. I am OK with this, so I leave the Member Virtual Host Root setting blank.
I hit save.
Now I have a new virtual host. I graceful restart to apply these changes.