Virtual Hosts
Each virtual host in OpenLiteSpeed has its own configuration file located under /usr/local/lsws/conf/vhosts/<vhost-name>/vhconf.conf.
Virtual Host Configuration Structure
Section titled “Virtual Host Configuration Structure”vhconf.conf docRoot index errorlog accesslog scriptHandler { } context(s) { } rewrite { } accessControl { } general { }Creating a Virtual Host
Section titled “Creating a Virtual Host”Via WebAdmin
Section titled “Via WebAdmin”- Navigate to Virtual Hosts in the left menu.
- Click Add to create a new virtual host.
- Fill in the name, document root, and config file path.
- Save and restart.
Via Config Files
Section titled “Via Config Files”Create the directory and config file:
mkdir -p /usr/local/lsws/conf/vhosts/example.comCreate /usr/local/lsws/conf/vhosts/example.com/vhconf.conf:
docRoot /var/www/example.com/public/
index { useServer 0 indexFiles index.php, index.html}
errorlog /usr/local/lsws/logs/example.com-error.log { useServer 0 logLevel WARN rollingSize 10M}
accesslog /usr/local/lsws/logs/example.com-access.log { useServer 0 logFormat "%h %l %u %t \"%r\" %>s %b" rollingSize 10M}Then reference it in httpd_config.conf:
virtualhost example.com { vhRoot /usr/local/lsws/conf/vhosts/example.com/ configFile $VH_ROOT/vhconf.conf allowSymbolLink 1 enableScript 1 restrained 1}
listener Default { address *:80 secure 0 map example.com example.com}Document Root
Section titled “Document Root”docRoot /var/www/example.com/public/The docRoot can use the $VH_ROOT variable:
docRoot $VH_ROOT/public/Script Handlers
Section titled “Script Handlers”Script handlers define how OLS processes dynamic content:
scriptHandler { add lsapi:lsphp83 php}This routes all .php files through the lsphp83 LSAPI handler.
Contexts
Section titled “Contexts”Contexts define per-directory or per-URI behavior:
context / { location $DOC_ROOT/ allowBrowse 1 indexFiles index.php, index.html}
context /protected/ { location $DOC_ROOT/protected/ allowBrowse 1 realm SiteRealm authName "Protected Area" required valid-user}
context /static/ { location $DOC_ROOT/static/ allowBrowse 1 enableExpires 1 expiresByType image/*=A604800, text/css=A604800, application/javascript=A604800}.htaccess Support with LiteHTTPD
Section titled “.htaccess Support with LiteHTTPD”OpenLiteSpeed has limited built-in .htaccess support. For full Apache-compatible .htaccess processing, use the LiteHTTPD module (ols_htaccess.so).
Enable .htaccess Processing
Section titled “Enable .htaccess Processing”In the virtual host config:
general { allowOverride All autoLoadHtaccess 1 configFile $VH_ROOT/vhconf.conf}- allowOverride — Controls which .htaccess directive categories are permitted. Values:
All,None, or a combination ofAuthConfig,FileInfo,Indexes,Limit,Options. - autoLoadHtaccess — When set to
1, OLS automatically loads and processes .htaccess files from the document root hierarchy.
With the LiteHTTPD module loaded, these settings enable full .htaccess support including rewrite rules, access control, MIME types, and more. See the directive reference for the complete list of supported directives.
Rewrite Rules
Section titled “Rewrite Rules”OLS supports rewrite rules in the virtual host config:
rewrite { enable 1 rules <<<END_rulesRewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ /index.php?$1 [L,QSA] END_rules}When using the LiteHTTPD module, rewrite rules can also be placed in .htaccess files.
Access Control
Section titled “Access Control”Per-vhost IP access control:
accessControl { allow ALL deny 192.168.1.100}Next Steps
Section titled “Next Steps”- Listeners — bind the virtual host to a listener.
- SSL / TLS — enable HTTPS for the virtual host.
- Custom Error Pages — configure error documents.
- Logs — per-vhost logging configuration.