Linux, Windows, Virtualization, OpenSource & Blogging

How to Create Virtual Hosts in OpenLiteSpeed Web Server

0

In our last article, we discussed the installation of OpenLiteSpeed on CentOS 7, Ubuntu 16.04, and Debian 9. Also, covered some of the important configurations such as Enabling support for PHP 7.0, Configure OpenLiteSpeed to use standard HTTP port 80, and MySQL DB Support.

Here are the links to the installation of OpenLiteSpeed,

READ: How to Install OpenLiteSpeed, PHP 7.0 & MariaDB on CentOS 7
READ: How to Install OpenLiteSpeed, PHP 7.0 & MariaDB on Ubuntu 16.04 / Debian 9

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

http://localhost:7080

OR

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

Create Virtual Hosts in OpenLiteSpeed web server:

Go to Virtual Hosts section and click on Add icon.

create Virtual Hosts in OpenLiteSpeed Web Server - Add Virtual Hosts
create Virtual Hosts in OpenLiteSpeed Web Server – Add Virtual Hosts

Add the below configuration:

Variables Value
Virtual Host Name web.itzgeek.local
Virtual Host Root $SERVER_ROOT/web.itzgeek.local/
Config File $SERVER_ROOT/conf/vhosts/$VH_NAME/web.itzgeek.local.conf
Follow Symbolic Link Yes
Enable Scripts/ExtApps Yes
Restrained Yes
ExtApp Set UID Mode Server UID
create Virtual Hosts in OpenLiteSpeed Web Server - Virtual Host Configuration
create Virtual Hosts in OpenLiteSpeed Web Server – Virtual Host Configuration

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

create Virtual Hosts in OpenLiteSpeed Web Server - OpenLiteSpeed Config File Creation Error
create Virtual Hosts in OpenLiteSpeed Web Server – OpenLiteSpeed Config File Creation Error

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

create Virtual Hosts in OpenLiteSpeed Web Server - OpenLiteSpeed Config File created
create Virtual Hosts in OpenLiteSpeed Web Server – OpenLiteSpeed Config File created

Final Configuration may look like this:

create Virtual Hosts in OpenLiteSpeed Web Server - Virtual Host Basic Configuration
create Virtual Hosts in OpenLiteSpeed Web Server – Virtual Host Basic Configuration

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

Variables Value
Document Root $VH_ROOT/html/
Domain Name web.itzgeek.local
Enable GZIP Compression Yes
Create Virtual Hosts in OpenLiteSpeed Web Server - OpenLiteSpeed Document Root
Create Virtual Hosts in OpenLiteSpeed Web Server – OpenLiteSpeed Document Root

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 (web.itzgeek.local) –> General –> Index Files. Set the index file name.

Variables Value
Use Server Index Files No
Index Files index.html
Auto Index No
Create Virtual Hosts in OpenLiteSpeed Web Server - OpenLiteSpeed Document Index
Create Virtual Hosts in OpenLiteSpeed Web Server – OpenLiteSpeed Document Index

Go to Virtual Hosts –> Choose Virtual Host (web.itzgeek.local) –> 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
Create Virtual Hosts in OpenLiteSpeed Web Server - OpenLiteSpeed Error Log
Create Virtual Hosts in OpenLiteSpeed Web Server – OpenLiteSpeed Error Log

Go to Virtual Hosts –> Choose Virtual Host (web.itzgeek.local) –> 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
Create Virtual Hosts in OpenLiteSpeed Web Server - OpenLiteSpeed Access Log
Create Virtual Hosts in OpenLiteSpeed Web Server – OpenLiteSpeed Access Log

Go to Virtual Hosts –> Choose Virtual Host (web.itzgeek.local) –> Log –>  Security. Allow everyone to access web pages.

Variables Value
Allowed List *
Create Virtual Hosts in OpenLiteSpeed Web Server - Access Controls
Create Virtual Hosts in OpenLiteSpeed Web Server – Access Controls

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

Create Virtual Hosts in OpenLiteSpeed Web Server - Listeners
Create Virtual Hosts in OpenLiteSpeed Web Server – Listeners

Now, add virtual host mapping.

Create Virtual Hosts in OpenLiteSpeed Web Server - Add Virtual Host Mapping
Create Virtual Hosts in OpenLiteSpeed Web Server – Add Virtual Host Mapping

Use the below details.

Variables Value
Virtual Host web.tzgeek.local
Domains web.itzgeek.local
Create Virtual Hosts in OpenLiteSpeed Web Server - OpenLiteSpeed Virtual Host Mapping
Create Virtual Hosts in OpenLiteSpeed Web Server – OpenLiteSpeed Virtual Host Mapping

Create Document root:

Now, create the document root and logs directory for the virtual host.

mkdir /usr/local/lsws/web.itzgeek.local/
mkdir /usr/local/lsws/web.itzgeek.local/{html,logs}

Create index.html with some content.

echo "This page served by OpenLiteSpeed Web Server running on Linux Operating System" > /usr/local/lsws/web.itzgeek.local/html/index.html

Restart the OpenLiteSpeed service.

Create Virtual Hosts in OpenLiteSpeed Web Server - Restart OpenLiteSpeed Service
Create Virtual Hosts in OpenLiteSpeed Web Server – Restart OpenLiteSpeed Service

The dashboard may look like below:

Create Virtual Hosts in OpenLiteSpeed Web Server - OpenLiteSpeed Dashboard
Create Virtual Hosts in OpenLiteSpeed Web Server – OpenLiteSpeed Dashboard

Verify Virtual Hosts in OpenLiteSpeed:

Visit the following URL using your favorite web browser.

http://yourfqdn

You can see the output like below:

Create Virtual Hosts in OpenLiteSpeed Web Server - Name Based Virtual Host
Create Virtual Hosts in OpenLiteSpeed Web Server – Name Based Virtual Host

That’s All. You have successfully configured Virtual Hosts on OpenLiteSpeed web server.

POSTS YOU MAY LIKE -:)

You might also like

How to Create Virtual Hosts in OpenLiteSpeed Web Server

0