? my $ctx = $main::context; ? $_mt->wrapper_file("wrapper.mt", "Configure", "Base Directives")->(sub {
This document describes the configuration directives common to all the protocols and handlers.
$ctx->{directive}->( name => "hosts", levels => [ qw(global) ], desc => q{Mapshost:port
to the mappings of per-host configs.},
)->(sub {
?>
The directive specifies the mapping between the authorities (the host or host:port
section of an URL) and their configurations.
The directive is mandatory, and must at least contain one entry.
When port
is omitted, the entry will match the requests targetting the default ports (i.e. port 80 for HTTP, port 443 for HTTPS) with given hostname.
Otherwise, the entry will match the requests targetting the specified port.
Since version 1.7, a wildcard character *
can be used as the first component of the hostname.
If used, they are matched using the rule defined in RFC 2818 Section 3.1.
For example, *.example.com
will match HTTP requests for both foo.example.com
and bar.example.com
.
Note that an exact match is preferred over host definitions using wildcard characters.
The mapping is searched using prefix-match.
The entry with the longest path is chosen when more than one matching paths were found.
An 404 Not Found
error is returned if no matching paths were found.
In releases prior to version 2.0, all the path entries are considered as directories. When H2O receives a request that exactly matches to an entry in paths that does not end with a slash, the server always returns a 301 redirect that appends a slash.
Since 2.0, it depends on the handler of the path whether if a 301 redirect that appends a slash is returned.
Server administrators can take advantage of this change to define per-path configurations (see the examples in file.file
and the FastCGI handler).
file.dir
is an exception that continues to perform the redirection; in case of the example above, access to /assets
is redirected to /assets/
.
In addition to specifying the port number, it is also possible to designate the bind address or the SSL configuration.
= $ctx->{example}->('Various ways of using the Listen Directive', <<'EOT') # accept HTTP on port 80 on default address (both IPv4 and IPv6) listen: 80 # accept HTTP on 127.0.0.1:8080 listen: host: 127.0.0.1 port: 8080 # accept HTTPS on port 443 listen: port: 443 ssl: key-file: /path/to/key-file certificate-file: /path/to/certificate-file # accept HTTPS on port 443 (using PROXY protocol) listen: port: 443 ssl: key-file: /path/to/key-file certificate-file: /path/to/certificate-file proxy-protocol: ON EOT ?>
The directive can be used either at global-level or at host-level.
At least one listen
directive must exist at the global level, or every host-level configuration must have at least one listen
directive.
Incoming connections accepted by global-level listeners will be dispatched to one of the host-level contexts with the corresponding host:port
, or to the first host-level context if none of the contexts were given host:port
corresponding to the request.
Host-level listeners specify bind addresses specific to the host-level context. However it is permitted to specify the same bind address for more than one host-level contexts, in which case hostname-based lookup will be performed between the host contexts that share the address. The feature is useful for setting up a HTTPS virtual host using Server-Name Indication (RFC 6066).
= $ctx->{example}->('Using host-level listeners for HTTPS virtual-hosting', <<'EOT') hosts: "www.example.com:443": listen: port: 443 ssl: key-file: /path/to/www_example_com.key certificate-file: /path/to/www_example_com.crt paths: "/": file.dir: /path/to/doc-root_of_www_example_com "www.example.jp:443": listen: port: 443 ssl: key-file: /path/to/www_example_jp.key certificate-file: /path/to/www_example_jp.crt paths: "/": file.dir: /path/to/doc-root_of_www_example_jp EOT ?>
The ssl
attribute must be defined as a mapping, and recognizes the following attributes.
SSLv2
, SSLv3
, TLSv1
, TLSv1.1
, TLSv1.2
.
Default is TLSv1
minimum-version
(introduced in version 2.2)
maximum-version
.
client
, server
.
Default is client
.
14400
(4 hours).
OFF
, H2O isolates RSA private key operations to an isolated process by using Neverbleed.
Default is ON
.
ssl-session-resumption
directive is provided for tuning parameters related to session resumption and session tickets.
The proxy-protocol
attribute (i.e. the value of the attribute must be either ON
or OFF
) specifies if the server should recognize the information passed via "the PROXY protocol in the incoming connections.
The protocol is used by L4 gateways such as AWS Elastic Load Balancing to send peer address to the servers behind the gateways.
When set to ON
, H2O standalone server tries to parse the first octets of the incoming connections as defined in version 1 of the specification, and if successful, passes the addresses obtained from the protocol to the web applications and the logging handlers.
If the first octets do not accord with the specification, it is considered as the start of the SSL handshake or as the beginning of an HTTP request depending on whether if the ssl
attribute has been used.
Default is OFF
.
If the type
attribute is set to unix
, then the port
attribute is assumed to specify the path of the unix socket to which the standalone server should bound.
Also following attributes are recognized.
error-log.emit-request-errors
EOT
desc => q{Path of the file to which error logs should be appended.},
)->(sub {
?>
Default is stderr.
If the path starts with |
, the rest of the path is considered as a command to which the logs should be piped.
access-log
error-log
EOT
default => "error-log.emit-request-errors: ON",
desc => q{Sets whether if request-level errors should be emitted to the error log.},
)->(sub {
?>
By setting the value to OFF
and by using the %{error}x
specifier of the access-log directive, it is possible to log request-level errors only to the access log.
? })
$ctx->{directive}->(
name => "handshake-timeout",
levels => [ qw(global) ],
default => "handshake-timeout: 10",
desc => q{Maximum time (in seconds) that can be spent by a connection before it becomes ready to accept an HTTP request.},
)->(sub {
?>
Times spent for receiving the PROXY protocol and TLS handshake are counted.
? })
$ctx->{directive}->(
name => "limit-request-body",
levels => [ qw(global) ],
desc => q{Maximum size of request body in bytes (e.g. content of POST).},
)->(sub {
?>
Default is 1073741824 (1GB).
? }) $ctx->{directive}->( name => "max-connections", levels => [ qw(global) ], default => 'max-connections: 1024', desc => q{Number of connections to handle at once at maximum.}, )->(sub {}); $ctx->{directive}->( name => "max-delegations", levels => [ qw(global) ], default => 'max-delegations: 5', desc => q{Limits the number of delegations (i.e. internal redirects using theX-Reproxy-URL
header).},
)->(sub {});
$ctx->{directive}->(
name => "num-name-resolution-threads",
levels => [ qw(global) ],
default => 'num-name-resolution-threads: 32',
desc => q{Maximum number of threads to run for name resolution.},
)->(sub {});
?>
$ctx->{directive}->(
name => "num-ocsp-updaters",
levels => [ qw(global) ],
since => "2.0",
default => 'num-ocsp-updaters: 10',
desc => q{Maximum number of OCSP updaters.},
)->(sub {
?>
OSCP Stapling is an optimization that speeds up the time spent for establishing a TLS connection. In order to staple OCSP information, a HTTP server is required to periodically contact the certificate authority. This directive caps the number of the processes spawn for collecting the information.
The use and the update interval of OCSP can be configured using the SSL attributes of the listen
configuration directive.
Default is the number of the processors connected to the system as obtained by getconf NPROCESSORS_ONLN
.
Default is none.
? }) $ctx->{directive}->( name => "tcp-fastopen", levels => [ qw(global) ], desc => q{Size of the queue used for TCP Fast Open.}, )->(sub { ?>
TCP Fast Open is an extension to the TCP/IP protocol that reduces the time spent for establishing a connection.
On Linux that support the feature, the default value is 4,096
.
On other platforms the default value is 0
(disabled).
ON
or OFF
) indicating whether if the server
response header should be sent.},
default => q{send-server-name: ON},
see_also => render_mt(<<'EOT'),
server-name
EOT
)->(sub {
?>
? })
$ctx->{directive}->(
name => "server-name",
levels => [ qw(global) ],
since => '2.0',
desc => q{Lets the user override the value of the server
response header.},
see_also => render_mt(<<'EOT'),
send-server-name
EOT
)->(sub {
?>
The default value is h2o/VERSION-NUMBER
.
? })
$ctx->{directive}->(
name => "setenv",
levels => [ qw(global host path extension) ],
since => '2.0',
desc => 'Sets one or more environment variables.',
see_also => render_mt(<<'EOT'),
unsetenv
EOT
)->(sub {
?>
Environment variables are a set of key-value pairs containing arbitrary strings, that can be read from applications invoked by the standalone server (e.g. fastcgi handler, mruby handler) and the access logger.
The directive is applied from outer-level to inner-level.
At each level, the directive is applied after the unsetenv
directive at the corresponding level is applied.
Environment variables are retained through internal redirections.
= $ctx->{example}->('Setting an environment variable namedFOO
', <<'EOT')
setenv:
FOO: "value_of_FOO"
EOT
?>
? })
$ctx->{directive}->(
name => "unsetenv",
levels => [ qw(global host path extension) ],
since => '2.0',
desc => 'Unsets one or more environment variables.',
see_also => render_mt(<<'EOT'),
setenv
EOT
)->(sub {
?>
The directive can be used to have an exception for the paths that have an environment variable set, or can be used to reset variables after an internal redirection.
= $ctx->{example}->('Setting environment variable forexample.com
excluding /specific-path
', <<'EOT')
hosts:
example.com:
setenv:
FOO: "value_of_FOO"
paths:
/specific-path:
unsetenv:
- FOO
...
EOT
?>
? })
$ctx->{directive}->(
name => "ssl-session-resumption",
levels => [ qw(global) ],
desc => q{Configures cache-based and ticket-based session resumption.},
)->(sub {
?>
To reduce the latency introduced by the TLS (SSL) handshake, two methods to resume a previous encrypted session are defined by the Internet Engineering Task Force. H2O supports both of the methods: cache-based session resumption (defined in RFC 5246) and ticket-based session resumption (defined in RFC 5077).
= $ctx->{example}->('Various session-resumption configurations', <<'EOT'); # use both methods (storing data on internal memory) ssl-session-resumption: mode: all # use both methods (storing data on memcached running at 192.168.0.4:11211) ssl-session-resumption: mode: all cache-store: memcached ticket-store: memcached cache-memcached-num-threads: 8 memcached: host: 192.168.0.4 port: 11211 # use ticket-based resumption only (with secrets used for encrypting the tickets stored in a file) ssl-session-resumption: mode: ticket ticket-store: file ticket-file: /path/to/ticket-secrets.yaml EOT ?>
The mode
attribute defines which methods should be used for resuming the TLS sessions.
The value can be either of: off
, cache
, ticket
, all
.
Default is all
.
If set to off
, session resumption will be disabled, and all TLS connections will be established via full handshakes.
If set to all
, both session-based and ticket-based resumptions will be used, with the preference given to the ticket-based resumption for clients supporting both the methods.
For each method, additional attributes can be used to customize their behaviors. Attributes that modify the behavior of the disabled method are ignored.
Following attributes are recognized if the cache-based session resumption is enabled.
Note that memcached
attribute must be defined as well in case the memcached
cache-store is used.
defines where the cache should be stored, must be one of: internal
, memcached
.
Default is internal
.
Please note that if you compiled h2o with OpenSSL 1.1.0 ~ 1.1.0f, session resumption with external cache store would fail due to bug of OpenSSL.
1
.
memcached
store specifies the key prefix used to store the secrets on memcached.
Default is h2o:ssl-session-cache:
.
Ticket-based session resumption uses master secret(s) to encrypt the keys used for encrypting the data transmitted over TLS connections. To achieve forward-secrecy (i.e. protect past communications from being decrypted in case a master secret gets obtained by a third party), it is essential to periodically change the secret and remove the old ones.
Among the three types of stores supported for ticket-based session resumption, the internal
store and memcached
store implement automatic roll-over of the secrets.
A new master secret is created every 1/4 of the session lifetime (defined by the lifetime
attribute), and they expire (and gets removed) after 5/4 of the session lifetime elapse.
For the file
store, it is the responsibility of the web-site administrator to periodically update the secrets. H2O monitors the file and reloads the secrets when the file is altered.
Following attributes are recognized if the ticket-based resumption is enabled.
internal
, file
, memcached
.
Default is internal
.
EVP_get_cipherbyname
.
Default is aes-256-cbc
.
EVP_get_digestbyname
.
Default is sha-256
.
file
store specifies the file in which the secrets are storedmemcached
store specifies the key used to store the secrets on memcached.
Default is h2o:ssl-session-ticket
.
Following attributes are common to cache-based and ticket-based session resumption.
3600
(in seconds).
memcached
stores.
The value must be a mapping with host
attribute specifying the address of the memcached server, and optionally a port
attribute specifying the port number (default is 11211
).
By default, the memcached client uses the BINARY protocol.
Users can opt-in to using the legacy ASCII protocol by adding a protocol
attribute set to ASCII
.
user
EOT
)->(sub {
?>
H2O uses an internal structure called h2o_buffer_t
for buffering various kinds of data (e.g. POST content, response from upstream HTTP or FastCGI server).
When amount of the data allocated in the buffer exceeds 32MB, it starts allocating storage from the directory pointed to by the directive.
By using the directive, users can set the directory to one within a memory-backed file system (e.g. tmpfs) for speed, or specify a disk-based file system to avoid memory pressure.
Note that the directory must be writable by the running user of the server.
? }) $ctx->{directive}->( name => "user", levels => [ qw(global) ], desc => q{Username under which the server should handle incoming requests.}, )->(sub { ?>
If the directive is omitted and if the server is started under root privileges, the server will attempt to setuid
to nobody
.
h2o
receives a fatal signal.},
default => q{crash-handler: "${H2O_ROOT}/share/h2o/annotate-backtrace-symbols"},
since => "2.1",
)->(sub {
?>
Note: this feature is only available when linking to the GNU libc.
The script is invoked if one of the SIGABRT
,
SIGBUS
, SIGFPE
, SIGILL
or
SIGSEGV
signals is received by h2o
.
h2o
writes the backtrace as provided by
backtrace()
and backtrace_symbols_fd
to the
standard input of the program.
If the path is not absolute, it is prefixed with ${H2O_ROOT}/
.
h2o
should wait for the crash handler pipe to close before exiting.},
default => q{crash-handler.wait-pipe-close: OFF},
since => "2.1",
)->(sub {
?>
When this setting is ON
, h2o
will wait
for the pipe to the crash handler to be closed before exiting.
This can be useful if you use a custom handler that inspects the dying
process.