Actions

Help

Difference between revisions of "Virtual Host Templates"

From OpenLiteSpeed Wiki

Line 3: Line 3:
 
__TOC__
 
__TOC__
  
== Setup ==
+
== Configuration ==
  
 
Virtual host template settings are located in the Virtual Host Templates tab in the WebAdmin console (one of the main tabs under configuration).
 
Virtual host template settings are located in the Virtual Host Templates tab in the WebAdmin console (one of the main tabs under configuration).
  
=== Default virtual host templates ===
+
=== Making your own templates ===
  
By default, OpenLiteSpeed comes with three virtual host templates for three common types of virtual hosts:
+
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, including the location of your template file (required). If you do not have a template file yet, that is OK. OpenLiteSpeed will give you the option to create the template file if you stipulate a file that does not exist (located in <code>$SERVER_ROOT/conf/templates/</code>).
  
* centralConfigLog: This template is for basic virtual hosts that all use the same server root directories and share a regular system for naming their root directories, document roots, etc... This template is examined in detail in the Example section below.
+
=== $VH_NAME variable ===
* PHP_SuEXEC: This template contains a PHP external application set up to run in suEXEC mode. (PHP scripts for these vhosts will be executed as the owner of the virtual host's document root.)
 
* EasyRailsWithSuEXEC: This template is an easy way to set up Ruby on Rails applications. The template contains a context that causes scripts in the virtual host to be run with Ruby (and as the owner of the vhost's document root).
 
  
We have made other [[Help:Custom_Templates|custom templates]] that you can import into OpenLiteSpeed. Importation instructions are included in each template's guide, though all you have to do is copy the template (an XML file) into <code>$SERVER_ROOT/conf/templates/</code> and then add a template that is directed to the XML file in the WebAdmin console.
+
Most settings in a virtual host template are comparable to normal virtual host settings. There is, however, a special variable: <code>$VH_NAME</code>. <code>$VH_NAME</code> 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 use of the <code>$VH_NAME</code> variable. This is so that different member vhosts will have different roots depending on their name. (This is further pursued in the example below.)
  
=== Making your own templates ===
+
== Adding member virtual hosts ==
  
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 <code>$SERVER_ROOT/conf/templates/</code>) and you will be given the option to have OpenLiteSpeed create the template file.
+
By itself, a template has no virtual hosts or websites. When you are ready to add virtual hosts with the template's 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.
  
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?
+
When you add a member virtual host, OpenLiteSpeed will not automatically create a virtual host root for this site. You must manually create a directory in the correct location (stipulated in either the Default Virtual Host Root setting or Member Virtual Host Root setting).
  
=== Virtual host template settings ===
+
=== Instantiating a member virtual host ===
  
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, <code>$VH_NAME</code>. <code>$VH_NAME</code> 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 <code>$VH_NAME</code>. This is so that different member vhosts will have different roots depending on their name. (This is further pursued in the example below.)
+
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).
  
=== Adding member virtual hosts ===
+
== Default virtual host templates ==
  
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 <code>$VH_NAME</code> appears in the template settings the virtual host name of the particular member virtual host will be used.
+
By default, OpenLiteSpeed comes with three virtual host templates for three common types of virtual hosts:
  
=== Instantiating a member virtual host ===
+
* centralConfigLog: This template is for basic virtual hosts that all use the same server root directories and share a regular system for naming their root directories, document roots, etc... This template is examined in detail in the Example section below.
 +
* PHP_SuEXEC: This template contains a PHP external application set up to run in suEXEC mode. (PHP scripts for these vhosts will be executed as the owner of the virtual host's document root.)
 +
* EasyRailsWithSuEXEC: This template is an easy way to set up Ruby on Rails applications. The template contains a context that causes scripts in the virtual host to be run with Ruby (and as the owner of the vhost's document root).
  
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).
+
We have made other [[Help:Custom_Templates|custom templates]] that you can import into OpenLiteSpeed. Importation instructions are included in each template's guide, though all you have to do is copy the template (an XML file) into <code>/usr/local/lsws/conf/templates/</code> and then, in the WebAdmin console, add a template that is directed to the XML file.
  
== Example ==
+
== Example: Creating a virtual host with a template ==
  
 
As an example we will be creating a member vhost named "test" in the centralConfigLog template.  
 
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.
+
=== Add the member virtual host ===
 +
 
 +
First, I go to the template centralConfigLog in WebAdmin console > Configuration > Virtual Host Template.
  
 
[[File:CentralConfigLog_Template.png|thumb|center|600px]]
 
[[File:CentralConfigLog_Template.png|thumb|center|600px]]

Revision as of 19:28, 12 December 2014

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.

Configuration

Virtual host template settings are located in the Virtual Host Templates tab in the WebAdmin console (one of the main tabs under configuration).

Making your own templates

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, including the location of your template file (required). If you do not have a template file yet, that is OK. OpenLiteSpeed will give you the option to create the template file if you stipulate a file that does not exist (located in $SERVER_ROOT/conf/templates/).

$VH_NAME variable

Most settings in a virtual host template are comparable to normal virtual host settings. There is, however, a special variable: $VH_NAME. $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 use of the $VH_NAME variable. This is so that different member vhosts will have different roots depending on their name. (This is further pursued in the example below.)

Adding member virtual hosts

By itself, a template has no virtual hosts or websites. When you are ready to add virtual hosts with the template's 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.

When you add a member virtual host, OpenLiteSpeed will not automatically create a virtual host root for this site. You must manually create a directory in the correct location (stipulated in either the Default Virtual Host Root setting or Member Virtual Host Root setting).

Instantiating a member virtual host

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).

Default virtual host templates

By default, OpenLiteSpeed comes with three virtual host templates for three common types of virtual hosts:

  • centralConfigLog: This template is for basic virtual hosts that all use the same server root directories and share a regular system for naming their root directories, document roots, etc... This template is examined in detail in the Example section below.
  • PHP_SuEXEC: This template contains a PHP external application set up to run in suEXEC mode. (PHP scripts for these vhosts will be executed as the owner of the virtual host's document root.)
  • EasyRailsWithSuEXEC: This template is an easy way to set up Ruby on Rails applications. The template contains a context that causes scripts in the virtual host to be run with Ruby (and as the owner of the vhost's document root).

We have made other custom templates that you can import into OpenLiteSpeed. Importation instructions are included in each template's guide, though all you have to do is copy the template (an XML file) into /usr/local/lsws/conf/templates/ and then, in the WebAdmin console, add a template that is directed to the XML file.

Example: Creating a virtual host with a template

As an example we will be creating a member vhost named "test" in the centralConfigLog template.

Add the member virtual host

First, I go to the template centralConfigLog in WebAdmin console > Configuration > Virtual Host Template.

CentralConfigLog Template.png

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.

Template General Settings.png

I start to add a new member virtual host by going to the Template tab and clicking Add on the Member Virtual Hosts table.

Add Member VHost.png

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 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.

Member VHost Settings.png

Now I have a new virtual host. I graceful restart to apply these changes.

Template Graceful Restart.png