By default, OpenLiteSpeed will have the Auto Index function disabled.
Auto Index can be enabled at the server level, vhost level & context level, and each sub-level will override a parent-level setting. E.g. the context-level setting will override the vhost-level setting. This can be done by logging into the WebAdmin Console at https://SERVER_IP:7080
, then following the instructions below.
Enable/Disable Auto Index at the Server Level:
Server Configuration > General > Index Files
Index Files: The default values are index.html
and index.php
separated by ,
Auto Index: Set to Yes
to enable Auto Index, and set to No
or Not Set
to disable Auto Index.
Auto Index URI: The script to generate the index, by default (when empty) will use /usr/local/lsws/share/autoindex/default.php
Enable/Disable Auto Index at the Vhost Level
Virtual Hosts > General > Index Files
Use Server Index Files: Set inherited index files named at the server level, or set the vhost’s own index file list. If set to Addition
, it will add additional file names for index files to the server-level configuration.
Index Files: Default values are index.html
and index.php
separated by ,
.
Auto Index: Set to Yes
to enable Auto Index, set to No
to disable it, or set to Not Set
to inherit the server-level setting.
Auto Index URI: The script to generate the index, by default (when empty) will use /usr/local/lsws/share/autoindex/default.php
These options will override the server-level configuration.
Enable/Disable Auto Index at the Context Level
If you want to disable Auto Index for all except for one or a few specific directories, you can achieve this with context settings.
Virtual Hosts > Context > +
Create a Static Context, and choose a URL. In this example, we will use /test/
URI: /test/
(do not miss the /
at end)
Location: $DOC_ROOT/test/
. This can be an absolute path e.g. /home/domain.com/public_html/test/
or a relative path with $DOC_ROOT
or $VH_ROOT
e.g $DOC_ROOT/test/
or $VH_ROOT/public_html/test/
.
Accessible: Yes
Index Files: Set the index file name for this context.
Auto Index: Enable, disable, or inherit Auto Index for this context.
How to Customize the Auto Index Page
This is the default Auto Index page:
The script used for Auto Index is /usr/local/lsws/share/autoindex/default.php
. You can create your own script or edit the default one to further customize it.
For example, the following PHP code lists the files in the directory:
<?php
$list = scandir(getenv('LS_AI_PATH'));
echo "Directory to be indexed: " .getenv('LS_AI_PATH'). "<br>";
print_r($list);
The environment variable LS_AI_PATH is used to pass the directory that needs to be indexed to the script: