Migrating from apache2 to OpenLiteSpeed (OLS)

#1
I have been using Apache2 web server behind Nginx reverse proxy for several years.
I recently read that OLS is much faster than Apache2, so I started testing.

The Nginx reverse proxy server manages TLS (LE) certs. It is configured so that when a user enters the URL
Code:
example.com
http://example.com
https://example.com
www.example.com
http://www.example.com
https://www.example.com
it is always redirected to
Code:
https://www.example.com
This is all solved by the Nginx reverse proxy.
The nginx reverse proxy communicates with Apache2 unencrypted on port 80, because encryption is provided by Nginx.
I want to leave everything as is and replace Apache with OLS.
So far I've launched a website without www, but not www.
I would like to put the config file here, but I don't know where it is located.

By the way, my apache config looks like this
Code:
<VirtualHost *:80>
    ServerAdmin admin@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/www.example.com/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    RemoteIPHeader X-Real-IP
    RemoteIPInternalProxy 192.168.20.10
  <Directory "/var/www/www.example.com">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
  </Directory>
</VirtualHost>
How should I configure OLS to work properly?
 
Last edited:

Cold-Egg

Administrator
#2
In the future, maybe you can consider to setup an OpenliteSpeed to handle the https and websites without a proxy.
The force www and SSL can be done by the following rewriterules.
Code:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
To set up a virtual host with OLS, you can use the web admin GUI to configure the necessary settings.
 
#3
Thank you very much for the information. I am just getting to know OLS.
Even before reading your message, my config contained this (I replaced my real domain with example.com)

Code:
docRoot                   $VH_ROOT/html
vhDomain                  example.com
vhAliases                 www.example.com
enableGzip                1

index  {
  useServer               0
  indexFiles              index.html
  autoIndex               0
}

rewrite  {
  enable                  1
  rules                   <<<END_rules
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
  END_rules

}
Of course, I did that before configuring OLS.

Code:
sudo mkdir /usr/local/lsws/www.example.com
sudo mkdir /usr/local/lsws/www.example.com/{conf,html,logs}
sudo chown lsadm:lsadm /usr/local/lsws/www.example.com/conf
sudo nano /usr/local/lsws/www.example.com/html/index.html
HTML:
<html>
    <head>
        <title>Welcome to OLS</title>
    </head>
    <body>
        <h1>Welcome to OLS</h1>
    </body>
</html>
If I use this configuration, the redirection works correctly, but the web page does not display.
If I cancel rewrite in the settings and remove this code

Code:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
The configuration looks like this:

Code:
docRoot                   $VH_ROOT/html
vhDomain                  example.com
vhAliases                 www.example.com
enableGzip                1

index  {
  useServer               0
  indexFiles              index.html
  autoIndex               0
}
Redirecting to https: // www of course doesn't work, but I can see the content of the website.
 
#5
Key Points Before Configuring OLS

You already have the reverse proxy doing:
So OLS only needs to:
  • Accept HTTP requests from Nginx
  • Serve the correct site based on Host header
  • Provide the correct document root
OLS configuration is fully done inside:

/usr/local/lsws/conf/

The virtual hosts are normally stored in:

/usr/local/lsws/conf/vhosts/<vhostname>/vhost.conf

And the main server-wide config file is:

/usr/local/lsws/conf/httpd_config.conf

You do NOT edit Apache-style configs.


Step-by-step: Create an OLS Virtual Host for example.com + www.example.com

1. Log in to the OLS WebAdmin Panel

Usually:

https://server-ip:7080


✅ 2. Create a new Virtual Host

WebAdmin → Virtual Hosts → Add

Suggested settings:

Setting Value Virtual Host NameexampleVirtual Host Root/usr/local/lsws/example.com/Config Fileconf/vhost.confEnable ScriptsYesRestrainedNo

Press Save.

Create directories:

mkdir -p /usr/local/lsws/example.com/{conf,html}
chown -R lsadm:lsadm /usr/local/lsws/example.com


✅ 3. Add Listeners for Port 80

OLS normally has a default listener on port 80 called DefaultListener.

Go to:

Listeners → DefaultListener → View/Edit → Virtual Host Mappings

Add mapping:

Field Value Virtual HostexampleDomainsexample.com, www.example.com

This duplicates what Apache’s:

ServerName example.com
ServerAlias www.example.com

did.

Important:

If you only entered example.com earlier, then www. will not work — this is usually the reason your WWW version failed.


✅ 4. Create /usr/local/lsws/example.com/conf/vhost.conf

Example config:

docRoot /var/www/www.example.com/
indexFiles index.php, index.html

allowSymbolLink 1
enableScript 1
restrained 0

errorlog logs/error.log
accesslog logs/access.log

<virtualHost example>
docRoot /var/www/www.example.com/
</virtualHost>

scripthandler {
add lsapi:lsphp php
}

phpIniOverride {
php_admin_value open_basedir "/var/www/www.example.com/:/tmp/"
}


✅ 5. Configure External App (PHP LSAPI)

If needed:

WebAdmin → Server Configuration → External App → Add

Type: lsapi
Name: lsphp
Address: uds://tmp/lshttpd/lsphp.sock
Max Connections: 10
Initial Request Timeout: 60
Retry Timeout: 0

Then link it to the virtual host:

Virtual Hosts → example → Script Handler → Add

Suffix: php
Handler Type: lsapi
Handler Name: lsphp

✅ 6. Restart OpenLiteSpeed

systemctl restart lsws


Why WWW didn’t work before

The OLS listener needs a domain mapping for every Host header that can be received.

Apache did this automatically via:

ServerAlias www.example.com

OLS needs:

example.com, www.example.com

If www.example.com is missing from the listener mapping, OLS returns 404 or default site.


What to Do If You Want to Copy Apache's Document Root

Your Apache config:

DocumentRoot /var/www/www.example.com/

You can safely use the same path in OLS:

docRoot /var/www/www.example.com/

OLS does not care — it’s just files.
 
Top