Name-Based Virtual Hosting
From OpenLiteSpeed Wiki
Revision as of 21:00, 28 August 2014 by Marmstrong
Name-based virtual hosting assigns virtual hosts based on domain names, not IP addresses. With name-based virtual hosting, you can host more than one website (virtual host) on each IP address.
Use the following guidelines to set up name-based virtual hosting:
Set up DNS properly
Forward the domain names of your web sites to the IP address used by your web server. This is commonly done by adding an "A" name entry to the DNS zone file for the website. This is not part of your OpenLiteSpeed configurations.
Set up the virtual hosts in the WebAdmin console
Create a virtual host for each website
First, make the virtual host's directories. I will name my virtual host "Example3" (because I've used Example and Example2 for other guides). In the command line, I go to my LSWS directory and make the following directories:
I then make conf owned by lsadm:lsadm (the WebAdmin console user) so that only the WebAdmin console will be able to manipulate configurations. (You should not allow other users permission to manipulate your configuration.):
chown lsadm:lsadm Example3/conf
Then I go to the WebAdmin console > Configuration > Virtual Hosts > Add to add the virtual hosts to OpenLiteSpeed:
You have to enter the virtual host's name, the virtual host root file, and the virtual host configuration file. You also need to choose whether to enable scripts on this site and whether users can access content outside of this virtual host root from the site (Restrained).
I don't have a virtual host configuration file yet, because I'm starting from scratch, so I tell OpenLiteSpeed to make one for me:
Then I save, go back into the virtual host's configurations, and specify my document root:
Create and assign listeners
Go to the WebAdmin console > Configuration > Listeners.
You can have one listener to listen on all local IP addresses, or you can create multiple listeners with each listener only listening to a specific IP address. Many users will find it simpler to have one listener that is then mapped to different domains, but having multiple listeners can be useful if, for example, you wish to set aside certain server processors for certain sites (see the listener binding section of LSWS's documentation) or conduct special functions on separate ports.
I don't need anything special, so I just go to the Default listener (that listens to all IPs on port 80):
And add a new mapping:
And input the domain for my virtual host: (In the Domains setting, "your.domain" will match to both "www.your.domain" and "your.domain". The leading "www." in a domain name is ignored.)
And I'm done!
Note: OpenLiteSpeed supports Server Name Indication (SNI), allowing users to set SSL certificates at the virtual host level. This means that virtual hosts (websites) with different SSL certificates can operate on the the same IP address and port number. Different listeners (and IP-based hosting) are not necessary for secure sites to have unique certificates.