5. Configuration
The configuration is defined on three levels :- command line : when the built-in server is used, the directory
where the server-specific configuration script is located can be specified
python Karrigell.py [ServerConfigDirectory]
By default, the directory used is the same as the one where Karrigell.py stands
- server configuration script : defines directories used by the framework, and
options relevant at the server level (session storage, maximum number of
threads, etc). For the built-in web server, these data are stored in the script
server_config.py in the Server Configuration Directory defined above
- host configuration scripts : defined in the script conf.py in each host data directory ; for localhost, it is located in the folder data/www
Each host can be configured by a specific configuration file. The mapping between a host name and its configuration file is defined in the plain text file hosts in the Server Configuration Directory
You can edit the host configuration script either with a text editor, or online from the Administration menu, accessible from the home page
5.1 Server configuration
This script defines the following values :
karrigell_dir
The directory where the core Karrigell framework is installed : the one where the folders core and package stand
host_conf_dir
The directory where the host-specific configuration text file hosts is located
port
The port where the server runspersistent_sessions
In most situations, it is better to set this option toTrue
, meaning that session data is stored on disk : storing it in memory is not safe in a multi threaded environment, either with the built-in multi-threaded server or behind ApacheThis limits session data to types that can be serialized by the pickle module
In case you need to store unpicklable Python objects as session data, you can set persistent_sessions to
False
. As mentioned above, be aware that this will only work reliably with a mono-process, mono-thread server such as the built-in Karrigell_monoprocess.py or Karrigell_async.pycache
Boolean to specify if HTTP caching should be used (with headerIf-Modified-Since
). Defaults to Trueipv6
Boolean to specify if IPv6 should be used instead of IPv4. Defaults to Falsemax_threads
The maximum number of threads than can be run by the multi-threaded built-in web serverprocess_num
The number of processes launched when the multi-process built-in web server is startedsilent
A boolean value to indicate if the server should write a logging info on sys.stderr for each requestmodules
A dictionary mapping name of steps in request processing to a list of modules. When the specified step is reached, the functionmain()
of each module is applied to the request handler object
5.2 Host configuration
The values that can be set are :
root_dir
Set theroot_dir
option to the full name of the Root Directory, the one from which you'll want to serve files. The default is the folderwww
in the Server Directorydata_dir
The directory where host-specific data stands : users database, translation file, session datacache_dir
The directory where script cache stands. The cache avoids parsing scripts each time they are run ; it is updated when the source code of a script is modified
If set toNone
, script caching is disabledcgi_dir
The directory where CGI scripts are locatedallow_directory_listing
The list of user roles (see authentication) that can see directory listings if a url matches a directory with no index file in it. IfNone
is in the list, all users can see the listings If value is['admin','edit']
, only users with one of the roles 'admin' or 'visit' will see a listing ; other users will get an error message
Defaults to[None]
hide_extensions
A list of file extensions that will be hidden (return error 403)ignore
A list of regular expression patterns that will be matched to url paths ; if a match succeeds then the server will return error 403
This can be used to forbid access to a set of directories. For instance if you have a version control that creates directories namedcvs
you can forbid access to them with this line :ignore = [".*/cvs/.*"]
logging_file
The path of a logging file. If not set, no logging is performedlogging_rotate
Iflogging_file
is set, indicate when the log file should be changed. If set toNone
, the same log file is always used. If set to"monthly", "daily"
or"hourly"
, the logging file changes with the month, the day or the hour ; the name of the logging file is the one set inloggin_file
, with the month / day / hour appendedoutput_encoding
A string = the encoding to use to send data back to the clientalias
A dictionary mapping an alias to the path of a folder in the file system. For instance :then the url htpp://localhost/scripts/index.html will serve the filedebug
indicates if you want detailed information, including the Python traceback, to be printed in case of error or exception during script execution. Defaults toTrue
. If set toFalse
, only a message like "Server was unable to process the request" will be printed, without any other detailgzip
If set toTrue
, and the user agent supports gzip encoding (most browsers do), the server compresses the data sent to the user agent for text files. This reduces network load, but slows down the server a littleglobal_modules
A list of paths to the modules which must be imported in every script run by Karrigell. If you have a line likethe module nameglobal_modules = ["/usr/scripts/myScript.py"]myScript
will be available in the namespace of all scriptsmax_sessions
The maximum number of sessions that can be stored. Defaults to 500