Configuration Examples

How Can We Help?
< Back
You are here:
Print

OpenLiteSpeed Configuration Examples

You can install OpenLiteSpeed in multiple ways, and each way may associate OLS configuration files in different locations. The purpose of this article is not to cover the various default configurations for different installation methods, but instead to show you some basic OLS configuration example files to give you a good starting point for a new server. We are assuming that you download the package from the website and install from the package (binary install).

Server Root

Normally the default OLS server root is /usr/local/lsws. Almost all default files for OLS will be under the server root. Of course, for newly created virtual hosts, you are free to use /home/user1/, /home/user2/, etc. for the virtual host root.

Main Configuration File

The most important configuration files are located in /usr/local/lsws/conf/, with httpd_config.conf being the main OLS configuration. Here’s an example of the contents of that file:

httpdWorkers 1
user nobody
group nobody
priority 0
cpuAffinity 2
enableLVE 0
inMemBufSize 60M
swappingDir /tmp/lshttpd/swap
autoFix503 1
gracefulRestartTimeout 300
mime $SERVER_ROOT/conf/mime.properties
showVersionNumber 1
useIpInProxyHeader 0
adminEmails root@localhost

errorlog $SERVER_ROOT/logs/error.log {
logLevel DEBUG
debugLevel 10
rollingSize 10M
enableStderrLog 1
}

accesslog $SERVER_ROOT/logs/access.log {
rollingSize 10M
keepDays 30
compressArchive 0
}
indexFiles index.html, index.php

expires {
enableExpires 1
expiresByType image/*=A604800, text/css=A604800, application/x-javascript=A604800
}
autoLoadHtaccess 1

tuning {
maxConnections 2000
maxSSLConnections 1000
connTimeout 300
maxKeepAliveReq 1000
smartKeepAlive 0
keepAliveTimeout 5
sndBufSize 0
rcvBufSize 0
maxReqURLLen 8192
maxReqHeaderSize 16380
maxReqBodySize 2047M
maxDynRespHeaderSize 8192
maxDynRespSize 2047M
maxCachedFileSize 4096
totalInMemCacheSize 20M
maxMMapFileSize 256K
totalMMapCacheSize 40M
useSendfile 1
fileETag 28
enableGzipCompress 1
compressibleTypes text/*,application/x-javascript,application/javascript,application/xml, image/svg+xml
enableDynGzipCompress 1
gzipCompressLevel 6
gzipAutoUpdateStatic 1
gzipStaticCompressLevel 6
gzipMaxFileSize 10M
gzipMinFileSize 300
}

fileAccessControl {
followSymbolLink 1
checkSymbolLink 0
requiredPermissionMask 000
restrictedPermissionMask 000
}

perClientConnLimit {
staticReqPerSec 0
dynReqPerSec 0
outBandwidth 0
inBandwidth 0
softLimit 10000
hardLimit 10000
gracePeriod 15
banPeriod 300
}

CGIRLimit {
maxCGIInstances 20
minUID 11
minGID 10
priority 0
CPUSoftLimit 10
CPUHardLimit 50
memSoftLimit 1460M
memHardLimit 1470M
procSoftLimit 400
procHardLimit 450
}

accessDenyDir {
dir /
dir /etc/*
dir /dev/*
dir $SERVER_ROOT/conf/*
dir $SERVER_ROOT/admin/conf/*
}

accessControl {
allow ALL
}

extprocessor lsphp {
type lsapi
address uds://tmp/lshttpd/lsphp.sock
maxConns 35
env PHP_LSAPI_MAX_REQUESTS=50
env PHP_LSAPI_CHILDREN=35
initTimeout 60
retryTimeout 0
persistConn 1
respBuffer 0
autoStart 2
path $SERVER_ROOT/fcgi-bin/lsphpnew
backlog 100
instances 1
runOnStartUp 3
priority 0
memSoftLimit 2047M
memHardLimit 2047M
procSoftLimit 400
procHardLimit 500
}

scripthandler {
add lsapi:lsphp php
}

railsDefaults {
maxConns 5
env LSAPI_MAX_IDLE=60
initTimeout 60
retryTimeout 0
pcKeepAliveTimeout 60
respBuffer 0
backlog 50
runOnStartUp 1
extMaxIdleTime 300
priority 3
memSoftLimit 2047M
memHardLimit 2047M
procSoftLimit 500
procHardLimit 600
}

module cache {
# 0
checkPrivateCache 1
checkPublicCache 1
maxCacheObjSize 10000000
maxStaleAge 200
qsCache 1
reqCookieCache 1
respCookieCache 1
ignoreReqCacheCtrl 1
ignoreRespCacheCtrl 0

enableCache 0
expireInSeconds 3600
enablePrivateCache 0
privateExpireInSeconds 3600

ls_enabled 1
}

module mod_security {
modsecurity on|off
modsecurity_rules `
SecRuleEngine On
SecRule ARGS "@streq whee" "id:10,phase:2"
SecRule ARGS "@streq whee" "id:11,phase:2"
`
modsecurity_rules_file /rule/file/path
modsecurity_rules_remote key uri
}

virtualhost Example {
vhRoot /var/www/html/Example/
configFile $SERVER_ROOT/conf/vhosts/Example/vhconf.conf
allowSymbolLink 1
enableScript 1
restrained 1
setUIDMode 0
}

listener Default {
address *:80
secure 0
map Example *
}

listener Defaultssl {
address *:443
secure 1
keyFile /usr/local/lsws/conf/example.key
certFile /usr/local/lsws/conf/example.crt
map Example *
}

Virtual Host Configuration Files

Under /usr/local/lsws/conf/vhosts/, you will find a configuration file for each virtual host. /usr/local/lsws/conf/vhosts/Example/vhconf.conf is an example vhost configuration file which contains the following:

docRoot $VH_ROOT/html/
enableGzip 1

errorlog $VH_ROOT/logs/error.log {
useServer 1
logLevel DEBUG
rollingSize 10M
}

accesslog $VH_ROOT/logs/access.log {
useServer 0
rollingSize 10M
keepDays 30
compressArchive 0
}

index {
useServer 0
indexFiles index.html
autoIndex 0
autoIndexURI /_autoindex/default.php
}

errorpage 404 {
url /error404.html
}

scripthandler {
add lsapi:lsphp-example php
}

expires {
enableExpires 1
}

accessControl {
allow *
}

realm SampleProtectedArea {

userDB {
location conf/vhosts/Example/htpasswd
maxCacheSize 200
cacheTimeout 60
}

groupDB {
location conf/vhosts/Example/htgroup
maxCacheSize 200
cacheTimeout 60
}
}

extprocessor lsphp-example {
type lsapi
address uds://tmp/lshttpd/lsphp-example.sock
maxConns 35
env PHP_LSAPI_MAX_REQUESTS=5000
env PHP_LSAPI_CHILDREN=35
initTimeout 60
retryTimeout 0
persistConn 1
respBuffer 0
autoStart 2
path /usr/local/lsws/lsphp73/bin/lsphp
backlog 100
instances 1
extUser john
extGroup john
runOnStartUp 3
priority 0
memSoftLimit 2047M
memHardLimit 2047M
procSoftLimit 400
procHardLimit 500
}

context /docs/ {
location $SERVER_ROOT/docs/
allowBrowse 1
}

context /protected/ {
location protected/
allowBrowse 1
realm SampleProtectedArea
authName Protected
required user test

accessControl {
allow *
}
}

context /blocked/ {
allowBrowse 0
}

context /cgi-bin/ {
type cgi
location $VH_ROOT/cgi-bin/
}

rewrite {
enable 1
autoLoadHtaccess 1
logLevel 9
}

Editing Configuration Files

The best and easiest way to edit the OpenLiteSpeed configuration is through the WebAdmin Console. When using WebAdmin, there is no need for you to remember OLS configuration syntax, and it is much easier for a beginner with no prior knowledge of OpenLiteSpeed. OLS configuration files are plain text. If you are an advanced OLS user and know OLS syntax, then you are certainly encouraged to use vi to edit the configuration file directly. Don’t forget to restart OLS after any changes to the configuration.

Include Files

Normally the main OLS configuration file httpd_config.conf defines different virtual host configuration file locations. OLS gets all server and virtual host configurations through this main file.

Technically, you can use include files in the OLS configuration, however this is not currently supported by the WebAdmin Console. Support for include files is coming to WebAdmin in the future, but until is does, if you intend to use include files, then you must edit the configuration via text editor. Include files are specified at the highest level and can contain wildcards at any point in the specification.

For example:

include $SERVER_ROOT/conf/l1/*/*.conf

This will look for the directories in the $SERVER_ROOT/conf/l1 directory and then include all of the files in the immediate level below that (but only in that level) with the suffix .conf. For example $SERVER_ROOT/conf/l1/l2-1/sample1.conf and SERVER_ROOT/conf/l1/l2-2/sample2.conf would be included but not $SERVER_ROOT/conf/l1/sample3.conf (level above) or SERVER_ROOT/conf/l1/l2-1/l3/sample4.conf (level below).

Alternately, you may take advantage of DirectAdmin’s OpenLiteSpeed support, which does split OLS configurations into different include files.