H2O’s configuration is primarily managed through a YAML file. The default location is usually h2o.conf
or specified via the -c
flag.
Example:
listen: 8080
hosts:
"example.com":
paths:
"/":
file.dir: /var/www/example.com
A concise guide to the H2O web server, covering configuration, key features, and useful commands.
H2O’s configuration is primarily managed through a YAML file. The default location is usually Example:
|
Explanation of main configuration directives:
|
|
Specifies TLS listener with cert and key:
|
|
Enable OCSP stapling:
|
|
Enables early hints for HTTP/2
|
|
Reverse proxy to another server:
|
|
Preserves the original
|
|
Sets the keep-alive timeout.
|
H2O provides flexible caching mechanisms. You can configure cache based on file extensions or specific paths. Example:
This caches static content for an hour. |
Explanation of caching directives:
|
|
Enables Gzip compression.
|
|
Enables Brotli compression (if available).
|
|
Add custom MIME types for files.
|
|
Forward requests to a FastCGI server:
|
|
Execute mruby scripts to handle requests.
|
|
Example:
Starts H2O using the |
|
Graceful shutdown. |
|
Reopens log files. |
|
Initiates a graceful restart. |
|
Enables verbose logging for debugging purposes. |
|
Check the error log file for any issues. |
H2O comes with a variety of built-in modules that extend its functionality. Here’s a brief overview:
|
mruby handlers: |
Allows executing mruby scripts for custom request handling.
|
External handlers: |
Use external programs to handle requests via HTTP or other protocols. |
|
Configure access control rules based on IP addresses or other criteria.
|
|
Configures TLS ticket key for session resumption.
|