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:

VariablesValue
Virtual Host Nameweb.itzgeek.local
Virtual Host Root$SERVER_ROOT/web.itzgeek.local/
Config File$SERVER_ROOT/conf/vhosts/$VH_NAME/web.itzgeek.local.conf
Follow Symbolic LinkYes
Enable Scripts/ExtAppsYes
RestrainedYes
ExtApp Set UID ModeServer 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.

VariablesPathRemarks
$SERVER_ROOT/usr/local/lsws/A location where OpenLiteSpeed is present
$VH_ROOT/usr/local/lsws/$VH_NAMESpecifies 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_NAMEThe 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.

VariablesValue
Document Root$VH_ROOT/html/
Domain Nameweb.itzgeek.local
Enable GZIP CompressionYes
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,

VariablesPathRemarks
$VH_ROOT/html//usr/local/lsws/$VH_NAME/htmlThis the document root.

Go to Virtual Hosts –> Choose Virtual Host (web.itzgeek.local) –> General –> Index Files. Set the index file name.

VariablesValue
Use Server Index FilesNo
Index Filesindex.html
Auto IndexNo
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.

VariablesValue
Use Server’s LogYes
File Name$VH_ROOT/logs/error.log
Log LevelERROR
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.

VariablesValue
Log ControlOwn Log File
File Name$VH_ROOT/logs/access.log
Piped LoggerNot Set
Log FormatNot Set
Log HeadersNot Set
Rolling Size (bytes)10M
Keep Days30
Bytes logNot Set
Compress ArchiveYes
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.

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

VariablesValue
Virtual Hostweb.tzgeek.local
Domainsweb.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.

Further Reading

You might also like

How to Create Virtual Hosts in OpenLiteSpeed Web Server

0