The HTTP server, also refered to as httpd, handles HTTP requests as described in RFC 2616 with a few exceptions such as gateway and proxy functionality. (The same is true for servers written by NCSA and others.) The server supports ipv6 as long as the underlying mechanisms also do so.
The server implements numerous features such as SSL (Secure Sockets Layer), ESI (Erlang Scripting Interface), CGI (Common Gateway Interface), User Authentication(using Mnesia, dets or plain text database), Common Logfile Format (with or without disk_log(3) support), URL Aliasing, Action Mappings, Directory Listings and SSI (Server-Side Includes).
The configuration of the server is done using Apache-style configuration directives..
Allmost all server functionality has been implemented using an especially crafted server API, it is described in the Erlang Web Server API. This API can be used to advantage by all who wants to enhance the server core functionality, for example custom logging and authentication.
It is possible to start a number of Web servers in an embedded system using the services config parameter from an application config file. A minimal application config file (from now on referred to as inets.config) starting two HTTP servers typically looks as follows:
[{inets, [{services, [{httpd, "/var/tmp/server_root/conf/8888.conf"}, {httpd, "/var/tmp/server_root/conf/8080.conf"}] } ] } ].
or:
[{inets, [{services, [{httpd, [{file,"/var/tmp/server_root/conf/8888.conf"}]}, {httpd, [{file,"/var/tmp/server_root/conf/8080.conf"}]}] } ] } ].
According to the new syntax which allows more functionality in the configuration. The possible options here are a customer configurable request accept timeout, the default value is 15000 milliseconds, and some trace functionality to debug the http server. The syntax must match the following grammar:
httpd_service() -> {httpd, httpd()} httpd() -> [httpd_config()] | file() httpd_config() -> {file, file()} | {debug, debug()} | {accept_timeout, integer()} debug() -> disable | [debug_options()] debug_options() -> {all_functions, modules()} | {exported_functions, modules()} | {disable, modules()} modules() -> [atom()]
{file, file()} corresponds to the functionality of the old version.
{debug, debug()} is the new trace option. It can trace on all functions or only exported functions on choosen modules.
{accept_timeout, integer()} sets the wanted timeout value for the server to set up a request connection.
A server config file is specified for each HTTP server to be started. The server config file syntax and semantics is described in the run time configuration section.
An easy way to test the setup of inets webservers can be done by copying the example server root (UNIX: $INETS_ROOT/examples/server_root/conf/, Windows: %INETS_ROOT%\examples\server_root\conf\) to a specific installation directory (/var/tmp/server_root/conf in this example). Then manualy start the Erlang node, using inets.config.
$ erl -config ./inets Erlang (BEAM) emulator version 4.9 Eshell V4.9 (abort with ^G) 1> application:start(inets). ok
Now there should be two HTTP servers started listening on the ports 8888 and 8080. You can test it by using any browser or the inets HTTP client requesting the urls: http://localhost:8888 and http://localhost:8080
All functionality in the server can be configured using Apache-style configuration directives stored in a configuration file. A minimal configuration file could look something like:
ServerName web.server.net ServerRoot /var/tmp/server_root DocumentRoot /var/tmp/server_root/htdocs
E.i the syntax is Directive followed by a withspace followed by the value of the directive followed by a new line.
The available directives are described in the section Server Configuration Directives.
ServerName
fully-qualified domain nameServerName
sets the fully-qualified domain
name
of the server.
ServerRoot
directory-filenameServerRoot
defines a directory-filename
where the server has it's operational home, e.g. used to store
log files and system icons. Relative paths specified in the
config file refer to this directory-filename
.
DocumentRoot
directory-filenameDocumentRoot
points the Web server to the document
space from which to serve documents from. Unless matched by
a directive like Alias, the server appends the path
from the requested URL to the DocumentRoot
to make
the path to the document, for example:
DocumentRoot /usr/weband an access to
http://your.server.org/index.html
would refer to /usr/web/index.html
.
BindAddress
addressBindAddress *
BindAddress
defines which address the server will
listen to. If the argument is * then the server listens to
all addresses otherwise the server will only listen to the
address specified. Address can be given either as an IP
address or a hostname.Port
numberPort 80
Port
defines which port number
the server should
use (0 to 65535). Certain port numbers are reserved for
particular protocols, i.e. examine your
OS characteristics (UNIX: /etc/services, Windows:
) for a list
of reserved ports. The standard port for HTTP is 80.SocketType
typeSocketType ip_comm
SocketType
defines which underlying communication
type
to be used. Valid socket types are:
ip_comm
ssl
DisableChunkedTransferEncodingSend
true | falseKeepAlive
true | falseKeepAliveTimeout
secondsMaxBodyAction
actionMaxBodyAction close
MaxBodyAction
specifies the action to be taken when the
message body limit has been passed.
close
reply414
MaxBodySize
sizeMaxBodySize nolimit
MaxBodySize
limits the size
of the message
body of HTTP request. The reply to this is specified by the
MaxBodyAction
directive. Valid size is:
nolimit
integer()
MaxClients
numberMaxClients 150
MaxClients
limits the number
of simultaneous
requests that can be supported. No more than this number
of child server process's can be created.MaxHeaderAction
actionMaxHeaderAction close
MaxHeaderAction
specifies the action to be taken
when the message Header limit has been passed.
close
reply414
MaxHeaderSize
sizeMaxHeaderSize 10240
MaxHeaderSize
limits the size
of the message
header of HTTP request. The reply to this is specified by
the MaxHeaderAction
directive. Valid size is:
integer()
nolimit
MaxKeepAliveRequests
NumberOfRequests
DefaultType
mime-typemime-type
is used if an unknown type is
encountered.Modules
module module ...Modules mod_get mod_head mod_log
Modules
defines which Erlang Webserver API modules to be used in a
specific server setup. module
is a module in the code
path of the server which has been written in accordance with
the section Erlang Web Server API. The server executes
functionality in each module, from left to right (from now
on called Erlang Webserver API Module Sequence).
ServerAdmin
email-addressServerAdmin unknown@unknown
ServerAdmin
defines the email-address
of the
server administrator, to be included in any error messages
returned by the server. It may be worth setting up a dedicated
user for this because clients do not always state which server
they have comments about, for example:ServerAdmin www-admin@white-house.com
SSLCACertificateFile
filenameSSLCACertificateFile
points at a PEM encoded
certificate of the certification authorities. Read more
about PEM encoded certificates in the SSL application
documentation. Read more about PEM encoded certificates in
the SSL application documentation.
SSLCertificateFile
filenameSSLCertificateFile
points at a PEM encoded
certificate. Read more about PEM encoded certificates in
the SSL application documentation. The dummy certificate
server.pem (UNIX: $INETS/examples/server_root/ssl/, Windows: %INETS%\examples\server_root\ssl\
),
in the Inets distribution, can be used for test
purposes. Read more about PEM encoded certificates in
the SSL application documentation.SSLCertificateKeyFile
filenameSSLCertificateKeyFile
is used to point at a
certificate key file. This directive should only be used if
a certificate key has not been bundled with the certificate
file pointed at by SSLCertificateFile .
SSLVerifyClient
typetype
to:
SSLVerifyDepth
integerSSLCiphers
ciphersSSLCihers
is a colon separated list of ciphers.
SSLPasswordCallbackFunction
functionSSLPasswordCallbackFunction
function in module
SSLPasswordCallbackModule
is called in order to
retrieve the user's password.SSLPasswordCallbackModule
functionSSLPasswordCallbackFunction
function in the
SSLPasswordCallbackModule
module is called in order
to retrieve the user's password.
Alias
url-path directory-filenameurl-path
is mapped to local files that begins with
directory-filename
, for example:Alias /image /ftp/pub/imageand an access to
http://your.server.org/image/foo.gif
would refer to the
file /ftp/pub/image/foo.gif
.DirectoryIndex
file file ...DirectoryIndex
specifies a list of resources to
look for if a client requests a directory using a /
at the end of the directory name. file
depicts the
name of a file in the directory. Several files may be
given, in which case the server will return the first it
finds, for example:DirectoryIndex index.htmland access to
http://your.server.org/docs/
would
return http://your.server.org/docs/index.html
if it
existed.ScriptAlias
url-path directory-filenameurl-path
are mapped to scripts beginning with
directory-filename
, for example:ScriptAlias /cgi-bin/ /web/cgi-bin/and an access to
http://your.server.org/cgi-bin/foo
would cause the server to run the script
/web/cgi-bin/foo
.
ScritpNoCache
true | falseScriptNoCache true
ScritpTimeout
SecondsScriptTimeout 15
Action
mime-type cgi-scriptAction
adds an action, which will activate a
cgi-script
whenever a file of a certain
mime-type
is requested. It propagates the URL and
file path of the requested document using the standard CGI
PATH_INFO
and PATH_TRANSLATED
environment
variables.
Action text/plain /cgi-bin/log_and_deliver_text Action home-grown/mime-type1 /~bob/do_special_stuff
Script
method cgi-scriptScript
adds an action, which will activate a
cgi-script
whenever a file is requested using a certain
HTTP method
. The method
is either GET
or
POST
as defined in RFC 1945. It propagates the URL and
file path of the requested document using the standard CGI
PATH_INFO
and PATH_TRANSLATED
environment
variables.Script GET /cgi-bin/get Script POST /~bob/put_and_a_little_more
ErlScriptAlias
url-path
allowed-module allowed-module ...ErlScriptAlias
marks all URLs matching url-path
as erl scheme scripts. A
matching URL is mapped into a specific module and
function. The module must be one of the
allowed-module
:s. For example:
ErlScriptAlias /cgi-bin/hit_me httpd_example md4and a request to
http://your.server.org/cgi-bin/hit_me/httpd_example:yahoo
would refer to httpd_example:yahoo/2
.
ErlScriptNoCache
true | falseErlScriptNoCache
is set to true the server will add
http header fields that prevents proxies from caching the page.
This is generally a good idea for dynamic content, since the
content often vary between each request.ErlScriptNoCache true
ErlScriptTimeout
secondsErlScriptTimeout
sets the time in seconds the
server will wait between each chunk of data is delivered
through mod_esi:deliver/2 when the new Erl Scheme format,
that takes three argument is used.
ErlScriptTimeout 15
EvalScriptAlias
url-path allowed-module
allowed-module ...EvalScriptAlias
marks all URLs matching
url-path
as eval scheme
scripts. A matching URL is mapped into a specific module
and function. The module must be one of the
allowed-module
:s. For example:
EvalScriptAlias /cgi-bin/hit_me_to httpd_example md5and a request to
http://your.server.org/cgi-bin/hit_me_to/httpd_example:print("Hi!")
would refer to httpd_example:print/1
.
<Directory
regexp-filename>
<Directory>
and </Directory> are used
to enclose a group of directives which applies only to the
named directory and sub-directories of that
directory. regexp-filename
is an extended regular
expression (See regexp(3)
). For example:
<Directory /usr/local/httpd[12]/htdocs> AuthAccessPassword sOmEpAsSwOrD AuthDBType plain AuthName My Secret Garden AuthUserFile /var/tmp/server_root/auth/user AuthGroupFile /var/tmp/server_root/auth/group require user ragnar edward require group group1 allow from 123.145.244.5 </Directory>If multiple directory sections match the directory (or its parents), then the directives are applied with the shortest match first. For example if you have one directory section for
garden/
and one for garden/flowers
, the
garden/
section matches first.
AuthDBType
plain | dets | mnesiaAuthDBType
sets the type of authentication database
that is used for the directory.The key difference between the
different methods is that dynamic data can be saved when Mnesia
and Dets is used.
first_start/0
creates the schema
and the tables. The second function start/0
shall be used
in consecutive startups. start/0
Starts Mnesia and wait
for the tables to be initiated. This function must only be used
when the schema and the tables already is created.
-module(mnesia_test). -export([start/0,load_data/0]). -include("mod_auth.hrl"). first_start()-> mnesia:create_schema([node()]), mnesia:start(), mnesia:create_table(httpd_user, [{type,bag},{disc_copies,[node()]}, {attributes,record_info(fields,httpd_user)}]), mnesia:create_table(httpd_group, [{type,bag},{disc_copies,[node()]}, {attributes,record_info(fields,httpd_group)}]), mnesia:wait_for_tables([httpd_user,httpd_group],60000). start()-> mnesia:start(), mnesia:wait_for_tables([httpd_user,httpd_group],60000).To create the Mnesia tables we use two records defined in mod_auth.hrl so the file must be included.
first_start/0
creates a schema
that specify on which nodes the database shall reside. Then it
starts Mnesia and creates the tables. The first argument is the
name of the tables, the second argument is a list of options how
the table will be created, see Mnesia documentation for more
information. Since the current implementation of the
mod_auth_mnesia saves one row for each user the type must be
bag.
start/0
shall be used to start Mensia. It
starts Mnesia and wait for the tables to be loaded. Mnesia
use the directory specified as mnesia_dir
at startup
if specified, otherwise Mnesia use the current directory.
dets
and mnesia
storage methods allow
writing of dynamic user data to disk. plain
is a read
only method.
AuthUserFile
filenameAuthUserFile
sets the name of a file which
contains the list of users and passwords for user
authentication. filename
can be either absolute or
relative to the ServerRoot
.
plain
storage method, this file is a
plain text file, where each line contains a user name followed
by a colon, followed by the non-encrypted password.
The behavior is undefined if user names are duplicated. For
example:
ragnar:s7Xxv7 edward:wwjau8If using the
dets
storage method, the user database is
maintained by dets
and should not be edited by
hand. Use the API functions in mod_auth
module to create / edit the user database.
mnesia
storage
method.
AuthUserFile
is stored outside the document tree of the Web server. If it
is placed in the directory which it protects, clients will
be able to download it.
AuthGroupFile
filenameAuthGroupFile
sets the name of a file which contains the
list of user groups for user authentication. filename
can
be either absolute or relative to the ServerRoot
.
plain
storage method, the group file is
a plain text file, where each line contains a group name
followed by a colon, followed by the member user names
separated by spaces. For example:
group1: bob joe anteIf using the
dets
storage method, the group database is
maintained by dets
and should not be edited by
hand. Use the API for mod_auth
module to create / edit the group database.
mnesia
storage
method.
AuthGroupFile
is stored outside the document tree of the Web server. If it
is placed in the directory which it protects, clients will
be able to download it.
AuthName
auth-domainAuthName
sets the name of the authorization realm
(auth-domain
) for a directory. This string informs the
client about which user name and password to use.
AuthAccessPassword
passwordAuthAccessPassword
is set to other than
NoPassword the password is required for all API calls. If
the password is set to DummyPassword the password must be
changed before any other API calls. To secure the
authenticating data the password must be changed after the
webserver is started since it otherwise is written in
clear text in the configuration file.allow from
host host ...allow from all
allow
defines a set of hosts which should be
granted access to a given directory. host
is one of
the following:
all
regexp(3)
)
allow from 123.34.56.11 150.100.23The host 123.34.56.11 and all machines on the 150.100.23 subnet are allowed access.
deny from
host host ...deny from all
deny
defines a set of hosts which should not be
granted access to a given directory. host
is one of
the following:
all
regexp(3)
)
deny from 123.34.56.11 150.100.23The host 123.34.56.11 and all machines on the 150.100.23 subnet are denied access.
require
entity-name entity entity ...require
defines users which should be granted
access to a given directory using a secret password. The allowed
syntaxes are:
require user user-name user-name ...
require group group-name group-name ...
AccessFileName
FileName1
FileName2
AccessFileName
Specify which filenames that are
used for access-files. When a request comes every directory in
the path to the requested asset will be searched after files
with the names specified by this parameter. If such a file is
found the file will be parsed and the restrictions specified
in it will be applied to the request.
SecurityDataFile
filenameSecurityDataFile
sets the name of the security
modules for a directory. The filename can be either absolute
or relative to the ServerRoot
. This file is used to
store persistent data for the mod_security module.
SecurityDataFile
.
SecurityMaxRetries
integer() | infinitySecurityMaxRetries
specifies the maximum number of
tries to authenticate a user has before he is blocked
out. If a user successfully authenticates when he is
blocked, he will receive a 403 (Forbidden) response from the
server.SecurityBlockTime
integer() | infinitySecurityBlockTime
specifies the number of minutes a user
is blocked. After this amount of time, he automatically
regains access.
SecurityFailExpireTime
integer() | infinitySecurityFailExpireTime
specifies the number of
minutes a failed user authentication is remembered. If a user
authenticates after this amount of time, his previous failed
authentications are forgotten.SecurityAuthTimeout
integer() | infinitySecurityAuthTimeout
specifies the number of
seconds a successful user authentication is
remembered. After this time has passed, the authentication
will no longer be reported.SecurityCallbackModule
atom()SecurityCallbackModule
specifies the name of a callback
module.
ErrorLog
filenameErrorLog
defines the filename
of the error log
file to be used to log server errors. If the filename
does not begin with a slash (/
) it is assumed to be
relative to the ServerRoot, for example:
ErrorLog logs/error_log_8080and errors will be logged in the server root (
UNIX: $SERVER_ROOT/logs/error_log_8080, Windows: %SERVER_ROOT%\logs\error_log_8080
) space.
SecurityLog
filenameSecurityLog
defines the filename
of the
access log file to be used to log security events. If the
filename
does not begin with a slash (/
) it is
assumed to be relative to the ServerRoot. For example:
SecurityLog logs/security_log_8080and security events will be logged in the server root (
UNIX: $SERVER_ROOT/logs/security_log_8080, Windows: %SERVER_ROOT%\logs\security_log_8080
) space.
TransferLog
filenameTransferLog
defines the filename
of the
access log file to be used to log incoming requests. If the
filename
does not begin with a slash (/
) it is
assumed to be relative to the ServerRoot. For example:TransferLog logs/access_log_8080and errors will be logged in the server root (
UNIX: $SERVER_ROOT/logs/access_log_8080, Windows: %SERVER_ROOT%\logs\access_log_8080
) space.
DiskLogFormat
internal|externalDiskLogFormat
defines the file-format of the
log files see disk_log for more information.
If the internal file-format is used, the logfile
will be repaired after a crash. When a log file is repaired
data might get lost. When the external file-format is used
httpd will not start if the log file is broken. DiskLogFormat external
ErrorDiskLog
filenameErrorDiskLog
defines the filename
of the
(disk_log(3))
error log file to be used to log server
errors. If the filename
does not begin with a slash
(/
) it is assumed to be relative to the ServerRoot,
for example:ErrorDiskLog logs/error_disk_log_8080and errors will be logged in the server root (
UNIX: $SERVER_ROOT/logs/error_disk_log_8080, Windows: %SERVER_ROOT%\logs\error_disk_log_8080
) space.ErrorDiskLogSize
max-bytes
max-filesErrorDiskLogSize 512000
8
ErrorDiskLogSize
defines the
properties of the (disk_log(3))
error log file. The
disk_log(3)
error log file is of type wrap
log and max-bytes
will be written to each file
and max-files
will be used before the first file is
truncated and reused.SecurityDiskLog
filenameSecurityDiskLog
defines the filename
of the
(disk_log(3))
access log file which logs incoming
security events i.e authenticated requests.
If the filename
does not begin with a slash
(/
) it is assumed to be relative to the ServerRoot.SecurityDiskLogSize
max-bytes max-filesSecurityDiskLogSize 512000 8
SecurityDiskLogSize
defines the properties of the
disk_log(3)
access log file. The disk_log(3)
access log file is of type wrap log and
max-bytes
will be written to each file and
max-files
will be used before the first file is
truncated and reused.TransferDiskLog
filenameTransferDiskLog
defines the filename
of the
(disk_log(3))
access log file which logs incoming
requests. If the filename
does not begin with a slash
(/
) it is assumed to be relative to the
ServerRoot, for example:
TransferDiskLog logs/transfer_disk_log_8080and errors will be logged in the server root (
UNIX: $SERVER_ROOT/logs/transfer_disk_log_8080, Windows: %SERVER_ROOT%\logs\transfer_disk_log_8080
) space.TransferDiskLogSize
max-bytes max-filesTransferDiskLogSize 512000 8
TransferDiskLogSize
defines the properties of the
disk_log(3)
access log file. The disk_log(3)
access log file is of type wrap log and
max-bytes
will be written to each file and
max-files
will be used before the first file is truncated
and reused.Files delivered to the client are MIME typed according to RFC 1590. File suffixes are mapped to MIME types before file delivery.
The mapping between file suffixes and MIME types are specified in the mime.types file. The mime.types reside within the conf directory of the ServerRoot. MIME types may be added as required to the mime.types file and the DefaultType config directive can be used to specify a default mime type. An example of a very small mime.types file:
# MIME type Extension text/html html htm text/plain asc txt
If users of the webserver needs to manage authentication of webpages that are local to their user and do not have server administrative privileges. They can use the per-directory runtime configurable user-authentication scheme that Inets calls htaccess. It works the following way:
In every directory under the DocumentRoot
or under an
Alias
a user can place an access-file. An access-file
is a plain text file that specify the restrictions that
shall be considered before the webserver answer to a
request. If there are more than one access-file in the path
to the requested asset, the directives in the access-file in
the directory nearest the asset will be used.
Allow
from subnet subnet|from all from all
AllowOverRide
all | none |
Directives - None -
AllowOverRide
Specify which parameters that not
access-files in subdirectories are allowed to alter the value
for. If the parameter is set to none no more
access-files will be parsed.
AuthGroupFile
Filename - None -
GroupName: Member1 Member2 .... MemberN
AuthName
auth-domain - None -
AuthType
BasicBasic
AuthType
Specify which authentication scheme that shall
be used. Today only Basic Authenticating using UUEncoding of
the password and user ID is implemented. AuthUserFile
Filename - None -
AuthUserFile
indicate which file that contains the list
of users. Filename must contain the absolute path to the
file. The users name and password are not encrypted so do not
place the file with users in a directory that is accessible
via the webserver. The format of the file is one user per row
and every row contains User Name and Password separated by a
colon, for example:
UserName:Password UserName:Password
deny
from subnet subnet|from all<Limit
RequestMethods>
<Limit>
and </Limit> are used to enclose
a group of directives which applies only to requests using
the specified methods. If no request method is specified
all request methods are verified against the restrictions.
<Limit POST GET HEAD> order allow deny require group group1 allow from 123.145.244.5 </Limit>
order
allow deny | deny alloworder
, defines if the deny or allow control shall
be preformed first.
require
group group1 group2...|user user1 user2... - None -
The Inets HTTP server provides two ways of creating dynamic web pages, each with its own advantages and disadvantages.
First there are CGI-scripts that can be written in any programming language. CGI-scripts are standardized and supported by most webservers. The drawback with CGI-scripts is that they are resource intensive because of their design. CGI requires the server to fork a new OS process for each executable it needs to start.
Second there are ESI-functions that provide a tight and efficient interface to the execution of Erlang functions, this interface on the other hand is Inets specific.
The mod_cgi module makes it possible to execute CGI scripts in the server. A file that matches the definition of a ScriptAlias config directive is treated as a CGI script. A CGI script is executed by the server and it's output is returned to the client.
The CGI Script response comprises a message-header and a message-body, separated by a blank line. The message-header contains one or more header fields. The body may be empty. Example:
"Content-Type:text/plain\nAccept-Ranges:none\n\nsome very plain text"
The server will interpret the cgi-headers and most of them will be transformed into HTTP headers and sent back to the client together with the body.
Support for CGI-1.1 is implemented in accordance with the RFC 3875.
The erlang server interface is implemented by the module mod_esi.
The erl scheme is designed to mimic plain CGI, but without the extra overhead. An URL which calls an Erlang erl function has the following syntax (regular expression):
http://your.server.org/***/Module[:/]Function(?QueryString|/PathInfo)
*** above depends on how the ErlScriptAlias config directive has been used
The module (Module) referred to must be found in the code path, and it must define a function (Function) with an arity of two or three. It is preferable to implement a funtion with arity three as it permitts you to send chunks of the webpage beeing generated to the client during the generation phase instead of first generating the whole web page and then sending it to the client. The option to implement a function with arity two is only keept for backwardcompatibilty reasons. See mod_esi(3) for implementation details of the esi callback function.
The eval scheme is straight-forward and does not mimic the behavior of plain CGI. An URL which calls an Erlang eval function has the following syntax:
http://your.server.org/***/Mod:Func(Arg1,...,ArgN)
*** above depends on how the ErlScriptAlias config directive has been used
The module (Mod) referred to must be found in the code path, and data returned by the function (Func) is passed back to the client. Data returned from the function must furthermore take the form as specified in the CGI specification. See mod_esi(3) for implementation details of the esi callback function.
The eval scheme can seriously threaten the integrity of the Erlang node housing a Web server, for example: http://your.server.org/eval?httpd_example:print(atom_to_list(apply(erlang,halt,[]))) which effectively will close down the Erlang node, that is use the erl scheme instead, until this security breach has been fixed. Today there are no good way of solving this problem and therefore Eval Scheme may be removed in future release of Inets. |
There are three types of logs supported. Transfer logs, security logs and error logs. The de-facto standard Common Logfile Format is used for the transfer and security logging. There are numerous statistics programs available to analyze Common Logfile Format. The Common Logfile Format looks as follows:
remotehost rfc931 authuser [date] "request" status bytes
Internal server errors are recorde in the error log file. The format of this file is a more ad hoc format than the logs using Common Logfile Format, but conforms to the following syntax:
[date] access to path failed for remotehost, reason: reason
Server Side Includes enables the server to run code embedded in HTML pages to generate the response to the client.
Having the server parse HTML pages is a double edged sword! It can be costly for a heavily loaded server to perform parsing of HTML pages while sending them. Furthermore, it can be considered a security risk to have average users executing commands in the name of the Erlang node user. Carefully consider these items before activating server-side includes. |
The server must be told which filename extensions to be used
for the parsed files. These files, while very similar to HTML,
are not HTML and are thus not treated the same. Internally, the
server uses the magic MIME type text/x-server-parsed-html
to identify parsed documents. It will then perform a format
conversion to change these files into HTML for the
client. Update the mime.types
file, as described in the
Mime Type Settings, to tell the server which extension to use
for parsed files, for example:
text/x-server-parsed-html shtml shtm
This makes files ending with .shtml
and .shtm
into parsed files. Alternatively, if the performance hit is not a
problem, all HTML pages can be marked as parsed:
text/x-server-parsed-html html htm
All server-side include directives to the server are formatted as SGML comments within the HTML page. This is in case the document should ever find itself in the client's hands unparsed. Each directive has the following format:
<!--#command tag1="value1" tag2="value2" -->
Each command takes different arguments, most only accept one tag at a time. Here is a breakdown of the commands and their associated tags:
config
errmsg
sizefmt
bytes
or
abbrev
. bytes
for a formatted byte count
or abbrev
for an abbreviated version displaying
the number of kilobytes.
include
virtual
file
../
cannot be used in this pathname, nor
can absolute paths. As above, you can send other parsed
documents, but you cannot send CGI scripts.
echo
var
, whose value is the name of the variable you wish
to echo.
fsize
include
command. The resulting
format of this command is subject to the sizefmt
parameter to the config
command.
flastmod
include
command.
exec
cmd
/bin/sh
. All
of the variables defined below are defined, and can be
used in the command.
cgi
A number of variables are made available to parsed documents. In addition to the CGI variable set, the following variables are made available:
DOCUMENT_NAME
DOCUMENT_URI
/docs/tutorials/foo.shtml
).
QUERY_STRING_UNESCAPED
\
.
DATE_LOCAL
DATE_GMT
LAST_MODIFIED
The process of handling a HTTP request involves several steps such as:
To provide customization and extensibility of the HTTP servers request handling most of these steps are handled by one or more modules that may be replaced or removed at runtime, and ofcourse new ones can be added. For each request all modules will be traversed in the order specified by the modules directive in the server configuration file. Some parts mainly the communication related steps are considered server core functionallity and are not implemented using the Erlang Webserver API. A description of functionality implemented by the Erlang Webserver API is described in the section Inets Webserver Modules.
A module can use data generated by previous modules in the Erlang Webserver API module sequence or generate data to be used by consecutive Erlang Webserver API modules. This is made possible due to an internal list of key-value tuples, also refered to as interaction data.
Interaction data enforces module dependencies and should be avoided if possible. This means the order of modules in the Modules config directive is significant. |
Each module implements server functionality using the Erlang Webserver API should implement the following call back functions:
The latter functions are needed only when new config directives are to be introduced. For details see httpd(3)
The convention is that all modules implementing some webserver functionallity has the name mod_*. When configuring the webserver an appropriate selection of these modules should be present in the Module directve. Please note that there are some interaction dependencies to take into account so the order of the modules can not be totally random.
Runs CGI scripts whenever a file of a certain type or HTTP method (See RFC 1945) is requested.
Uses the following Erlang Webserver API interaction data, if available:
Exports the following Erlang Webserver API interaction data, if possible:
{new_request_uri, RequestURI}
RequestURI
has been generated.
This module makes it possible to map different parts of the host file system into the document tree e.i. creates aliases and redirections.
Exports the following Erlang Webserver API interaction data, if possible:
{real_name, PathData}
This module provides for basic user authentication using textual files, dets databases as well as mnesia databases.
Uses the following Erlang Webserver API interaction data, if available:
Exports the following Erlang Webserver API interaction data, if possible:
{remote_user, User}
This module handles invoking of CGI scripts
This module generates an HTML directory listing (Apache-style) if a client sends a request for a directory instead of a file. This module needs to be removed from the Modules config directive if directory listings is unwanted.
Uses the following Erlang Webserver API interaction data, if available:
Exports the following Erlang Webserver API interaction data, if possible:
{mime_type, MimeType}
MimeType
.
Standard logging using the "Common Logfile Format" and disk_log(3).
Uses the following Erlang Webserver API interaction data, if available:
This module implements the Erlang Server Interface (ESI) that provides a tight and efficient interface to the execution of Erlang functions.
Uses the following Erlang Webserver API interaction data, if available:
Exports the following Erlang Webserver API interaction data, if possible:
{mime_type, MimeType}
MimeType
This module is responsible for handling GET requests to regular files. GET requests for parts of files is handled by mod_range.
Uses the following Erlang Webserver API interaction data, if available:
This module is responsible for handling HEAD requests to regular files. HEAD requests for dynamic content is handled by each module responsible for dynamic content.
Uses the following Erlang Webserver API interaction data, if available:
This module provides per-directory user configurable access control.
Uses the following Erlang Webserver API interaction data, if available:
Exports the following Erlang Webserver API interaction data, if possible:
{remote_user_name, User}
This module makes it possible to expand "macros" embedded in HTML pages before they are delivered to the client, that is Server-Side Includes (SSI).
Uses the following Erlang Webserver API interaction data, if available:
Exports the following Erlang Webserver API interaction data, if possible:
{mime_type, MimeType}
MimeType
as defined in the Mime Type Settings
section.
Standard logging using the "Common Logfile Format" and text files.
Uses the following Erlang Webserver API interaction data, if available:
This module response to requests for one or many ranges of a file. This is especially useful when downloading large files, since a broken download may be resumed.
Note that request for multiple parts of a document will report a size of zero to the log file.
Uses the following Erlang Webserver API interaction data, if available:
This module controls that the conditions in the requests is fullfilled. For example a request may specify that the answer only is of interest if the content is unchanged since last retrieval. Or if the content is changed the range-request shall be converted to a request for the whole file instead.
If a client sends more then one of the header fields that
restricts the servers right to respond, the standard does not
specify how this shall be handled. httpd will control each
field in the following order and if one of the fields not match
the current state the request will be rejected with a proper
response.
1.If-modified
2.If-Unmodified
3.If-Match
4.If-Nomatch
Uses the following Erlang Webserver API interaction data, if available:
Exports the following Erlang Webserver API interaction data, if possible:
{if_range, send_file}
This module serves as a filter for authenticated requests handled in mod_auth. It provides possibility to restrict users from access for a specified amount of time if they fail to authenticate several times. It logs failed authentication as well as blocking of users, and it also calls a configurable call-back module when the events occur.
There is also an API to manually block, unblock and list blocked users or users, who have been authenticated within a configurable amount of time.
mod_trace is responsible for handling of TRACE requests. Trace is a new request method in HTTP/1.1. The intended use of trace requests is for testing. The body of the trace response is the request message that the responding Web server or proxy received.