Hello, friends. In this post, you will learn how to create a new VirtualHost on OpenLiteSpeed.
The term Virtual Host refers to making more than one Website work on a single machine. Virtual websites can be “IP-based”, which means that each website has a different IP address, or “name-based”, which means that with a single IP address, websites with different domain names are running
Apache was one of the first to support this feature but over time other web servers began to implement it. One of those servers is OpenLiteSpeed.
So, let us start the work.
Creating a new VirtualhHost on OpenLiteSpeed
The first thing you have to do is install and configure OpenLiteSpeed properly, in this case, I’m using CentOS but it’s the same process in both Ubuntu or Debian.
So, read our post about it
How to install OpenLiteSpeed on CentOS 8?
How to install OpenLiteSpeed on Ubuntu 20.04?
Then log in and you will see the dashboard.
On the left side, go to the VirtualHosts section to list them.
Now, you can create a new one by clicking on the + button on the right.
There you have to enter the data of the new VirtualHost. In my case, I have chosen the following values that you can modify as you wish.
Virtual Host Name test.osradar.local Virtual Host Root $SERVER_ROOT/test.osradar.local/ Config File $SERVER_ROOT/conf/vhosts/$VH_NAME/test.osradar.local.conf Follow Symbolic Link Yes Enable Scripts/ExtApps Yes Restrained Yes ExtApp Set UID Mode Server UID
Then, click on the Diskette button to save the changes.
As I have pointed out that a configuration file that does not exist, the following message will jump.
Click on the CLICK TO CREATE link to create it automatically. You will see the following screen.
Again click on the button to save the changes. And you will see the new Virtualhost created.
Configuring the new Virtualhost on OpenLiteSpeed
The new Virtualhost is already created, but it is convenient to make some configurations to leave it fully functional.
To do so, from the Virtualhost summary screen, click on the magnifying glass of the new virtualhost to see and modify its values.
In the General tab, you will see the basic information that is empty.
To enter data, click on the edit button on the right.
On the next screen, set the values you need. In my case, I have chosen the following:
Document Root $VH_ROOT/html/ Domain Name test.osradar.local Enable GZIP Compression Yes
Then click on the Save button.
Now do the same but in the Index Files section.
And in the Index File
field add the value index.php
Then click on the Save button.
Now we will configure the logs of the new VirtualHost that will help us to keep track of it.
So, go to the Log tab and you will see the default information and the Virtual Host Log and Access Log sections
Click the edit button in the Virtual Host Log section and set the values you need. In this case, I have chosen these.
Use Server’s Log Yes File Name $VH_ROOT/logs/error.log Log Level ERROR Rolling Size (bytes) 10M Keep Days 45
To save the changes, click on the Save button.
Now it’s time to work with the Access Log section. To do this, create a new one by clicking on the + button
And add the following values
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 45 Bytes log Not Set Compress Archive Yes
Then save the changes.
More configurations
The next step is to go to the Security tab and position ourselves in the Access Control section
This value is where we will specify the hosts that can access VirtualHost.
Click on the edit button and in the Allowed List field specify the Hosts. If you want it to be accessible to everyone, type *
Now click on the Save button.
Then, on the left side go to the Listeners section
There, in the Virtual Host Mappings section create a new entry by clicking on the + button
And choose your Virtualhost as follows
Then click on the Save button.
Now you can restart OpenLiteSpeed to apply all these changes.
Testing the new VirtualHost on OpenLiteSpeed
Now on your server, create the corresponding folders. Both the Document Root folder and the log folder.
mkdir -p /usr/local/lsws/test.osradar.local/{html,logs}
Then, create a test file:
nano /usr/local/lsws/test.osradar.local/html/index.html
And add some message
Now try to open it from your browser. In this case, access it using the name of the VirtualHost.
So, the new Virtualhost is working.
Conclusion
Having Virtual hosts on OpenLiteSpeed is an easy matter thanks to the administrator interface the program has. As we have shown you in this post.