H2O

the optimized HTTP/1.x, HTTP/2 server
Powered by Oktavia

Configure > Base Directives

This document describes the configuration directives common to all the protocols and handlers.

"hosts"

Description:

Maps host:port to the mappings of per-host configs.

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.

Example. A host redirecting all HTTP requests to HTTPS
hosts:
  "www.example.com:80":
    listen:
      port: 80
    paths:
      "/":
        redirect: https://www.example.com/
  "www.example.com:443":
    listen:
      port: 443
      ssl:
        key-file: /path/to/ssl-key-file
        certificate-file: /path/to/ssl-certificate-file
    paths:
      "/":
        file.dir: /path/to/doc-root
Level:
global

"paths"

Description:

Mapping of paths and their configurations.

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.

Example. Configuration with two paths
hosts:
  "www.example.com":
    listen:
      port: 80
    paths:
      "/":
        file.dir: /path/to/doc-root
      "/assets":
        file.dir: /path/to/assets
Level:
host

"listen"

Description:

Specifies the port at which the server should listen to.

In addition to specifying the port number, it is also possible to designate the bind address or the SSL configuration.

Example. Various ways of using the Listen Directive
# 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/key-file

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).

Example. Using host-level listeners for HTTPS virtual-hosting
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

The ssl entry recognizes the following attributes.

certificate-file:
path of the SSL certificate file (mandatory)
key-file:
path of the SSL private key file (mandatory)
minimum-version:
minimum protocol version, should be one of: SSLv2, SSLv3, TLSv1, TLSv1.1, TLSv1.2. Default is TLSv1
cipher-suite:
list of cipher suites to be passed to OpenSSL via SSL_CTX_set_cipher_list (optional)
cipher-preference:
side of the list that should be used for selecting the cipher-suite; should be either of: client, server. Default is client.
dh-file:
path of a PEM file containing the Diffie-Hellman paratemers to be used. Use of the file is recommended for servers using Diffie-Hellman key agreement. (optional)
ocsp-update-interval:
interval for updating the OCSP stapling data (in seconds), or set to zero to disable OCSP stapling. Default is 14400 (4 hours).
ocsp-max-failures
number of consecutive OCSP queriy failures before stopping to send OCSP stapling data to the client. Default is 3.
Level:
global, host

"error-log"

Description:

Path of the file to which error logs should be appended.

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.

Example. Log errors to file
error-log: /path/to/error-log-file
Example. Log errors through pipe
error-log: "| rotatelogs /path/to/error-log-file.%Y%m%d 86400"
Level:
global

"limit-request-body"

Description:

Maximum size of request body in bytes (e.g. content of POST).

Default is unlimited.

Level:
global

"max-connections"

Description:

Number of connections to handle at once at maximum.

Level:
global
Default:
max-connections: 1024

"max-delegations"

Description:

Limits the number of delegations (i.e. internal redirects using the X-Reproxy-URL header).

Level:
global
Default:
max-delegations: 5

"num-name-resolution-threads"

Description:

Number of threads to run for name resolution.

Level:
global
Default:
num-name-resolution-threads: 32

"num-threads"

Description:

Number of worker threads.

Default is the number of the processors connected to the system as obtained by getconf NPROCESSORS_ONLN.

Level:
global

"pid-file"

Description:

Name of the file to which the process id of the server should be written.

Default is none.

Level:
global

"user"

Description:

Username under which the server should handle incoming requests.

If the directive is omitted and if the server is started under root privileges, the server will attempt to setuid to nobody.

Level:
global