How to Create Virtual Hosts in OpenLiteSpeed Web Server

Creating Virtual Hosts in OpenLiteSpeed Web Server

In this article, we are going to see how to create a virtual host in OpenLiteSpeed webserver.

In our last article, we discussed the installation of OpenLiteSpeed on CentOS 7.

To begin, log in to OpenLiteSpeed WeAdmin console by going to below URL.

http://your-ip-add-ress:7080

Create Virtual Hosts in OpenLiteSpeed web server

Go to Virtual Hosts section and click on Add icon.

Add the below configuration:

Variables Value
Virtual Host Name mydomainname.in
Virtual Host Root $SERVER_ROOT/mydomainname.in/
Config File $SERVER_ROOT/conf/vhosts/$VH_NAME/mydomainname.in.conf
Follow Symbolic Link Yes
Enable Scripts/ExtApps Yes
Restrained Yes
ExtApp Set UID Mode Server UID

n the configuration, we have used variables for relative paths.

Variables Path Remarks
$SERVER_ROOT /usr/local/lsws/ A location where OpenLiteSpeed is present
$VH_ROOT /usr/local/lsws/$VH_NAME Specifies the root directory of the virtual host where all the files related to the virtual host (like log files, CGI scripts, etc). Note: This is NOT the document root
Config DIR /usr/local/lsws/conf/vhosts/$VH_NAME The configuration filename and directory for this virtual host

When you click on the save button; OpenLiteSpeed will through an error saying config file does not exist.

So, CLICK ON CREATE to let OpenLiteSpeed creates virtual host configuration file for you.

You would get a message like below on the successful creation of virtual host configuration file.

Now, Click Save.

Your configuration will be looks like:

Once the virtual host is created, go to Virtual Hosts –> Choose Virtual Host (you have created) –> General Tab and modify the configurations like shown below.

Variables Value
Document Root $VH_ROOT/html/
Domain Name mydomainname.com
Enable GZIP Compression Yes

Variables we have used here are,

Variables Path Remarks
$VH_ROOT/html/ /usr/local/lsws/$VH_NAME/html This the document root.

Go to Virtual Hosts –> Choose Virtual Host (you have created) –> General –> Index Files. Set the index file name.

Variables Value
Use Server Index Files No
Index Files index.html
Auto Index No

Go to Virtual Hosts –> Choose Virtual Host (You have created) –> Log —> Virtual Host Log. Set the log file to store OpenLiteSpeed error logs.

Variables Value
Use Server’s Log Yes
File Name $VH_ROOT/logs/error.log
Log Level ERROR
Rolling Size (bytes) 10M

Go to Virtual Hosts –> Choose Virtual Host (You have created) –> Log –> Access Log. Set the log file to store OpenLiteSpeed access logs.

Variables Value
Log Control Own Log File
File Name $VH_ROOT/logs/access.log
Piped Logger Not Set
Log Format Not Set
Log Headers Not Set
Rolling Size (bytes) 10M
Keep Days 30
Bytes log Not Set
Compress Archive Yes

Go to Virtual Hosts –> Choose Virtual Host  –> Security. Allow everyone to access web pages.

Enter ‘*‘ in Allow list.

Mapping Virtual Host in OpenLiteSpeed

Once you have configured a virtual host, you need to map the virtual host with specific domain so that you can access it via fully qualified domain. To do that, go to Listeners and click on Zoom icon view the Default listener.

Now, add virtual host mapping.

Use the below details.

Variables Value
Virtual Host mydomainname.com
Domains mydomainname.com

Create Document root

Now, create the document root and logs directory for the virtual host by logging into your SSH.

mkdir /usr/local/lsws/mydomainname.com/

mkdir /usr/local/lsws/mydomainname.com/{html,logs}

cd /usr/local/lsws/www.choose2host.in/html/

nano index.html

Add “This page served by OpenLiteSpeed Web Server running on CentOS 7 Operating System”

Now, restart the OpenLiteSpeed service.

Now, your Dashboard will look like the below screenshot with virtual hosts

Verify Virtual Hosts in OpenLiteSpeed

Now access http://mydomainname.com in your web browser to verify your virtual host.

Now, you have configured the virtual host in your OpenLiteSpeed web server, you can modify your index.html as you wish.

For installing and configuring Apache Tomcat 8.5, Click here

 

 

You may also like...