Context
In LiteSpeed web server, context is a set of resources that can be located by URLs with a common parent URL. The common parent URL is the ID of the context. A web site is comprised of contexts, for example, "/" is the root Context mapped to the document root of a web site; "/cgi-bin/" is Context dedicated to CGI applications. If you think your web site as a URL tree, then every branch is a context which can be identified by the URL of the branching node. A context should be explicitly defined for the following purposes:
  • To access file system outside of the document root.
  • To block access to certain resources.
  • To setup user level authentication for certain resources.
  • To create mount points for external applications.
  • To redirect requests to another location.
 
Table of Contents
General Context URI   Root   Accessible   Enable Expires   Expires Default   Expires By Type   Extra Headers   MIME Type   Force MIME Type   Default MIME Type   Auto Index   Index Files   Allow Override   Realm   Authentication Name   Required   Access Allowed   Access Denied   Authorizer   Add Default Charset   Customized Default Charset   Enable Rewrite   Rewrite Inherit   Rewrite Base   Rewrite Rules   Enable IP Geolocation   Apache Style Configurations   
Java Web App Context URI   Location   Servlet Engine   Enable Expires   Expires Default   Expires By Type   Extra Headers   Auto Index   Index Files   Allow Override   Realm   Authentication Name   Required   Access Allowed   Access Denied   Authorizer   Add Default Charset   Customized Default Charset   Enable IP Geolocation   
Servlet Context URI   Servlet Engine   Allow Override   Realm   Authentication Name   Required   Access Allowed   Access Denied   Authorizer   Add Default Charset   Customized Default Charset   Enable IP Geolocation   Extra Headers   
FastCGI Context URI   FastCGI App   Allow Override   Realm   Authentication Name   Required   Access Allowed   Access Denied   Authorizer   Add Default Charset   Customized Default Charset   Enable IP Geolocation   Extra Headers   
Proxy Context URI   Web Server   Add Default Charset   Customized Default Charset   Enable IP Geolocation   
CGI Context URI   Path   Allow Set UID   Allow Override   Realm   Authentication Name   Required   Access Allowed   Access Denied   Authorizer   Add Default Charset   Customized Default Charset   Extra Headers   Enable Rewrite   Rewrite Inherit   Rewrite Base   Rewrite Rules   Enable IP Geolocation   Apache Style Configurations   
Redirect Context URI   External Redirect   Status Code   Destination URI   Allow Override   Realm   Authentication Name   Required   Access Allowed   Access Denied   Authorizer   
Rack/Rails Context URI   Root   Run-time Mode   Max Connections   Enable Expires   Expires Default   Expires By Type   Extra Headers   MIME Type   Force MIME Type   Default MIME Type   Auto Index   Index Files   Allow Override   Realm   Authentication Name   Required   Access Allowed   Access Denied   Authorizer   Add Default Charset   Customized Default Charset   Enable IP Geolocation   
 
General ContextGo to top
Description: General context is used to bring in files outside of the document root like Apache's Alias or AliasMatch directive. It can also be used to protect a particular directory, either inside or outside of the document root, using authorization realms. General context can also be used to block or restrict access for a special directory within the document root.
URIGo to top
Description: Specifies the URI for this context. URI can be a plain URI (starting with "/") or a Perl compatible regular expression URI (starting with "exp:").

If a plain URI ends with a "/", then this context will include all sub-URIs under this URI. If the context maps to a directory on the file system, a trailing "/" must be added.

For examples, a plain URI like /examples/ with Root set to /home/john/web_examples will map the request "/examples/foo/bar.html" to file "/home/john/web_examples/foo/bar.html". To simulate Apache's mod_userdir, set URI to exp: ^/~([A-Za-z0-9]+)(.*), set Root to /home/$1/public_html$2, a request URI /~john/foo/bar.html will map to file /home/john/public_html/foo/bar.html.
Syntax: URI
See Also: Root
RootGo to top
Description: Specifies the corresponding location of this context in the file system. It can be an absolute path or relative path to $SERVER_ROOT, $VH_ROOT and $DOC_ROOT. $DOC_ROOT is the default relative path, and can be omitted.
If the URI is a regular expression, then matched sub-string can be used to form the 'Root' string. Matched sub-string can be referenced with '$1'-'$9', '$0' and '&' can be used to reference the whole matched string. Additionally, query string can be set by appending a '?' followed by the query string. Be careful, '&' should be escaped as '\&' in the query string.
Syntax: path
See Also: URI
AccessibleGo to top
Description: Specifies whether this context can be accessed. Set to No to deny access. You can use this feature to protect the specified directory from being visited. You may use it when you are updating contents for this context, or you have special data in this directory.
Syntax: Select from radio box
Enable ExpiresGo to top
Description: Specifies whether to generate Expires header for static files. If enabled, Expires header will be generated based on Expires Default and Expires By Type. This can be set at server, virtual host and context level. Lower level settings will override higher level ones, i.e. context settings will override the virtual host settings and virtual host settings will override the server settings.
Syntax: Select from radio box
Expires DefaultGo to top
Description: Specifies default settings for Expires header generation. This setting is effective when Enable Expires is set. It can be overridden by Expires By Type. Do not set this default at server or virtual host level unless you have to, since it will generate Expires header for all pages. Most of time this is set at context level for certain directories that do not change often. If there is no default setting, no Expires header will be generated for types not specified in Expires By Type.
Syntax: A|Mseconds
After base time(A|M) plus specified seconds, it will expire. Base time "A" means the client's access time and "M" means the file's last modified time.
Expires By TypeGo to top
Description: Specifies Expires settings for individual MIME types.
Syntax: Comma delimited list of "MIME-type=A|Mseconds". After base time(A|M) plus specified seconds, it will expire. Base time "A" means the client's access time and "M" means the file's last modified time. MIME-type can accept wildcard "*", like image/*.
Extra HeadersGo to top
Description: Specifies extra response headers to be added. Multiple headers can be added, one header per line.
Syntax: "[HeaderName]: [HeaderValue]" in each line.
example:
Cache-control: no-cache, no-store
My-header: Custom header value
MIME TypeGo to top
Description: Specifies additional MIME types and mappings for this context. New mappings will override existing mappings under this context and its children contexts.
Example:
image/jpg jpeg jpg, image/gif gif
If you want to show PHP scripts as text files instead of being executed as scripts, just override the .php mapping to MIME type "text/plain".
Syntax: MIME-type1 extension extension ..., MIME-type2 extension ... Use comma to separate between MIME types, use space to separate multiple extensions.
Force MIME TypeGo to top
Description: When specified, all files under this context will be served as static files with the MIME type specified regardless file suffix. When set to NONE, inherited force type setting will be disabled.
Syntax: MIME-type|NONE
Default MIME TypeGo to top
Description: When specified, this type will be used when MIME type mapping cannot be determined by the suffix of a document or no suffix. If not specified, default value application/octet-stream will be used.
Syntax: MIME-type
Auto IndexGo to top
Description: Specifies whether to generate directory index on the fly when index files listed in Index Files are not available in a directory. This option is customizable under virtual host and context level, and is inherited along the directory tree until it is explicitly overridden. You can customize the generated index page, please read How to customize auto index script?
Syntax: Select from radio box
Tips: [Security] It is recommended to turn off Auto Index wherever possible to prevent revealing confidential data.
See Also: Index Files, Auto Index URI
Index FilesGo to top
Description: Specifies names of index files that will be searched sequentially when a URL is mapped to a directory. You can customize it at server, virtual host and context level.
Syntax: comma delimited list of name of index files
Tips: [Performance] Only set index files that you need.
Allow OverrideGo to top
Description: Specifies what directives in an access control file are allowed. An access control file can be placed in a directory to control the accessibility to files under that directory.
  • When nothing is checked, inherited default settings will be used.
  • When None is checked, access control file will be ignored.
  • When Limit is checked, directives "Order", "Allow from" and "Deny from" are allowed.
  • When Auth is checked, directives "AuthGroupFile", "AuthName", "AuthType", "AuthUserFile", "Require" are allowed.
  • When FileInfo is checked, directives "Satisfy", AddDefaultCharset", "AddType", "DefaultType", "ForceType", "ExpiresActive", "ExpiresDefault", "ExpiresByType", "Redirect", "RedirectTemp", "RedirectPermanent", "RewriteEngine", "RewriteOptions", "RewriteBase", "RewriteCond" and "RewriteRule" are allowed
  • When Indexes is checked, directive "DirectoryIndex" is allowed
  • When Options is checked, directive "Options" is allowed
Allow Override configuration is available at three levels: server, virtual host and context. If server level configuration is not checked, the controlled directives will be disabled for the whole server no matter if it is enabled or not at lower levels. If server level is enabled, virtual host will inherit same settings by default, similarly context level will inherit virtual host settings. In other words, lower level can disable a setting that is enabled by upper level, but cannot enable a setting that is disabled by upper level.
Syntax: Select from checkbox
Tips: [Performance] If there is no need for directory level configuration customization, check None.
RealmGo to top
Description: Specifies the authorization realm for this context. When specified, a valid user name and password must be provided in order to access this context. Authorization Realms were set up in Virtual Host Security section. Here only use its Realm Name.
Syntax: Select from drop down list
Authentication NameGo to top
Description: Specifies an alternative name of the authorization realm for current context. If it is not specified, the original realm name will be used. Authentication name is displayed on the browser's login pop-up.
RequiredGo to top
Description: Specifies which user/group can access this context. With this directive, a large user database can be shared amongst contexts of different levels of permission.
Syntax: Syntax is compatible with Apache, valid syntaxes are
  • user username [username ...]
    Only listed users can access this context;
  • group groupid [groupid ...]
    Only users belong to listed groups can access this context.
If it is not specified, all valid users can access this resource.
Tips: user username [username ...] or group groupid [groupid ...]
Access AllowedGo to top
Description: Specifies which IP or sub-network is allowed to access resource under this context. Together with Access Denied and server/vhost level access control, the accessibility is determined by the smallest scope that client's IP address falls into.
Syntax: comma-delimited list of IP/sub-network. sub-network can be like 192.168.1.0/255.255.255.0, 192.168.1 or 192.168.1.*.
Access DeniedGo to top
Description: Specifies which IP or sub-network is NOT allowed to access resource under this context. Together with Access Allowed and server/vhost level access control, the accessibility is determined by the smallest scope that client's IP address falls into.
Syntax: comma-delimited list of IP/sub-network. sub-network can be like 192.168.1.0/255.255.255.0, 192.168.1 or 192.168.1.*.
AuthorizerGo to top
Description: Specifies an external application that can be used to generate authorized/unauthorized decision. Currently only FastCGI Authroizer is available. For more details about FastCGI AUTHORIZER role, please visit http://www.fastcgi.com.
Syntax: Select from drop down list
Add Default CharsetGo to top
Description: Specifies whether to add a character set tag to the "Content-Type" response header, when content type is either "text/html" or "text/plain" without any parameter. When set to Off, this function is disabled. When set to On, either character set specified by Customized Default Charset or the default "iso-8859-1" will be added.
Syntax: Select from radio box
Customized Default CharsetGo to top
Description: Specifies a character set to be used when Add Default Charset is On. This is optional. Default value is iso-8859-1. This entry has no effect when Add Default Charset is Off.
Syntax: name of a character set, like utf-8
Enable RewriteGo to top
Description: Specifies whether to enable LiteSpeed URL rewrite engine. This option can be customized at virtual host and context level, and is inherited along the directory tree until it is explicitly overridden.
Syntax: Select from radio box
Rewrite InheritGo to top
Description: Specifies whether to inherit rewrite rules from parent context. If rewrite is enabled and not inherited, rewrite base and rewrite rules defined in this context will be used.
Syntax: Select from radio box
Rewrite BaseGo to top
Description: Specifies the base URL for rewrite rules.
Syntax: URL
Rewrite RulesGo to top
Description: Specifies a list of rewrite rules at virtual host or context level. A rewrite rule is comprised of one RewriteRule directive and optionally preceded by multiple RewriteCond directives.
  • Each directive should take only one line.
  • RewriteCond and RewriteRule follow Apache's rewrite directive syntax, just copy and paste rewrite directives in your Apache configuration files over.
  • There are minor differences between LiteSpeed and Apache mod_rewrite implementation:
    • %\{LA-U:variable\} and %\{LA-F:variable\} are ignored by LiteSpeed rewrite engine,
    • two new server variables are added in LiteSpeed rewrite engine: %\{CURRENT_URI\} represents the current URI processed by rewrite engine; %\{SCRIPT_NAME\} has the same meaning as the corresponding CGI environment variable.
The implementation of LiteSpeed rewrite engine follows the specification of Apache rewrite engine, For more details about rewrite rules, please refer to Apache mod_rewrite document and Apache URL Rewriting guide.
Syntax: string
Enable IP GeolocationGo to top
Description: [Enterprise Edition Only] Specifies whether to enable IP to Geolocation lookup. It can be set at server, virtual host or context level.
Syntax: Select from radio box
See Also: Use Client IP in Header, DB File Path, DB Cache Type
Apache Style ConfigurationsGo to top
Description: Specifies Apache configuration directives that are supported by LiteSpeed. For example, default PHP configuration, php.ini entries, can be overridden by the server with 4 directives: "php_value", "php_flag", "php_admin_value" and "php_admin_flag".
Syntax: Same as Apache configuration file
Java Web App ContextGo to top
Description: Most Servlet engine has its own built-in HTTP server but they cannot efficiently serve static content or as fast as LiteSpeed server can. In order to improve the overall performance, LiteSpeed server can be configured as a gateway server, which serves static content and forwards dyanmic java page requests to the Servlet engine.
Without Java web app context, multiple contexts have to be created, including a general context that matches the root directory of the web application, Servlet contexts for each respective Servlet is defined in the web application's configuration file - WEB-INF/web.xml. It is awkward and troublesome. Java web app context is introduced to eliminate this hassle by importing a Java web application with only one context configuration. With java web app context, all required contexts are created automatically based on web application's configuration file.
There are a couple points you need to remember:
  • If the web application is packed into a war file, the war file must be expanded, the server cannot access files in compressed archive.
  • A Script Handler for .jsp files should be defined as well.
  • For same resources, the same URL should be used no matter whether it is accessed through LiteSpeed server or through the Servlet engine's built-in HTTP server.
    For example, the "examples" web application that comes with Tomcat should be imported. Tomcat 4.1 is installed under /opt/tomcat, files of "examples" web application is located at /opt/tomcat/webapps/examples/, through Tomcat's built-in HTTP server "examples" web application is accessed with URI like /examples/***. In order to use the same URI to access it, the context should be configured with: URI = /examples/, Root = /opt/tomcat/webapps/examples/.
URIGo to top
Description: Specifies the URI for this context. URI should start with a "/". If an URI ends with a "/" then this context will include all sub-URIs under this URI.
Syntax: URI
LocationGo to top
Description: Specifies the directory that contains the files for this web application. This is the directory containing the "WEB-INF/web.xml".
Syntax: path
Servlet EngineGo to top
Description: Specifies the name of the Servlet engine that serves this web application. Servlet engines are predefined in External Application section which can either be at server or virtual host level.
Syntax: Select from drop down list
Servlet ContextGo to top
Description: A single Servlet can be imported through Servlet context. Just specifies the URI for the Servlet and the name of the Servlet engine. You only need to use this when you do not want to import the whole web application or you want to protect different Servlets with different authorization realms. The URI has the same requirement as in Java Web App Context.
FastCGI ContextGo to top
Description: FastCGI application cannot be used directly. It must be either configured as a script handler or mapped to a URL through FastCGI context. A FastCGI context will associate a URI with a FastCGI application.
FastCGI AppGo to top
Description: Specifies the name of the FastCGI application. It is predefined in External Application section, which can be at server level or at virtual host level.
Syntax: Select from drop down list
Proxy ContextGo to top
Description: Proxy context enables this virtual host as a transparent reverse proxy server. Proxy server could be running in front of any web servers or application servers that supports the HTTP protocol. External web server has to be predefined in External Application.
Web ServerGo to top
Description: Specifies the name of the external web server. It is predefined in External Application section which can be at server or virtual host level.
Syntax: Select from drop down list
CGI ContextGo to top
Description: CGI context defines one CGI script or a group of CGI scripts. CGI scripts can be either inside or outside of the document root. When a file under the CGI directory is requested, the server will always try to execute it as a CGI script, no matter if its executable or not. In this way, file content is always protected under CGI context. It is recommended that you put all your CGI scripts in a directory and set up a CGI context.
PathGo to top
Description: Specifies the location of CGI scripts. Path can be a directory that contains a group of CGI scripts, like $VH_ROOT/myapp/cgi-bin/. In this case, context URI must end with "/" like /app1/cgi/. Path can also specify only one CGI script, like $VH_ROOT/myapp/myscript.pl with corresponding URI /myapp/myscript.pl.
Syntax: path
Allow Set UIDGo to top
Description: Specifies whether Set UID bit is allowed for CGI scripts. If Set UID bit is allowed and the Set UID bit is on for a CGI script, no matter which user the CGI script was started on behalf of, user id of the CGI process will switch to the user id of the owner of the CGI script.
Default is false.
Syntax: Select from radio box
Tips: [Security] Do not allow Set UID CGI script whenever possible as it is an inherent security risk.
Redirect ContextGo to top
Description: A Redirect Context can be used to forward one URI or a group of URIs to another location. The destination URI can be either on the same web site (internal redirect) or an absolute URI pointing to another web site (external redirect).
External RedirectGo to top
Description: Specifies whether this redirect is external. For external redirection, Status Code may be specified and Destination URI can start either with "/" or "http(s)://". For internal redirection, Destination URI must start with "/".
Status CodeGo to top
Description: Specifies the response status code of the external redirection. If the status code is between 300 and 399, Destination URI can be specified.
Syntax: Select from drop down list
Destination URIGo to top
Description: Specifies the target location of the redirection. If this redirected URI maps to a URI in another redirect context, it will be redirected again. This URI can either be a relative URI on the same web site starting with "/", or an absolute URI pointing to different web site starting with "http(s)://". If the URI contains regular expression, the destination can reference the matched variables such as $1, $2.
Rack/Rails ContextGo to top
Description: Rack/Rails context provides an easy way to configure a Ruby Rack/Rails application. To add a Rack/Rails application, only mounting URL and application's root directory is required. No need to go through all the trouble to define an external application, add 404 handler, rewrite rule, etc.
Run-time ModeGo to top
Description: Specifies which mode Rack/Rails will be running as, 'Development', 'Production' or 'Staging'. Default is 'Production'.
Syntax: Select from drop down list
Max ConnectionsGo to top
Description: Specifies the maximum concurrent connections that can be established between the web server and an external application. This setting controls how many requests can be processed concurrently by an external application. However, the real limit also depends on the external application itself. Set this value higher will not help if the external application is not fast enough or cannot scale to large number of concurrent requests.
Syntax: Integer number
Tips: [Performance] Setting a high value does not directly translate to higher performance. Set the limit to a value that will not overload the the external application will provide the best performance/throughput.