<-
Apache > HTTP Server > Documentation > Version 2.5 > Modules

Apache Module mod_http2

Available Languages:  en 

Description:Support for the HTTP/2 transport layer
Status:Extension
Module Identifier:http2_module
Source File:mod_http2.c
Compatibility:Available in version 2.4.17 and later

Summary

This module provides HTTP/2 (RFC 7540) support for the Apache HTTP Server.

This module relies on libnghttp2 to provide the core http/2 engine.

Warning

This module is experimental. Its behaviors, directives, and defaults are subject to more change from release to release relative to other standard modules. Users are encouraged to consult the "CHANGES" file for potential updates.

You must enable HTTP/2 via Protocols in order to use the functionality described in this document:

Protocols h2 http/1.1

Directives

top

H2Direct Directive

Description:H2 Direct Protocol Switch
Syntax:H2Direct on|off
Default:H2Direct on for http:, off for https: requests
Context:server config, virtual host
Status:Extension
Module:mod_http2

This directive toggles the usage of the HTTP/2 Direct Mode. This should be used inside a <VirtualHost> section to enable direct HTTP/2 communication for that virtual host.

Direct communication means that if the first bytes received by the server on a connection match the HTTP/2 preamble, the HTTP/2 protocol is switched to immediately without further negotiation. This mode is defined in RFC 7540 for the cleartext (h2c) case. Its use on TLS connections not mandated by the standard.

This mode only has an effect when h2 or h2c is enabled via the <Protocols>.

Example

H2Direct on
top

H2MaxSessionStreams Directive

Description:Maximum number of active streams per HTTP/2 session.
Syntax:H2MaxSessionStreams n
Default:H2MaxSessionStreams 100
Context:server config, virtual host
Status:Extension
Module:mod_http2

This directive sets the maximum number of active streams per HTTP/2 session (e.g. connection) that the server allows. A stream is active if it is not idle or closed according to RFC 7540.

Example

H2MaxSessionStreams 20
top

H2MaxWorkerIdleSeconds Directive

Description:Maximum number of seconds h2 workers remain idle until shut down.
Syntax:H2MaxWorkerIdleSeconds n
Default:H2MaxWorkerIdleSeconds 600
Context:server config
Status:Extension
Module:mod_http2

This directive sets the maximum number of seconds a h2 worker may idle until it shuts itself down. This only happens while the number of h2 workers exceeds H2MinWorkers.

Example

H2MaxWorkerIdleSeconds 20
top

H2MaxWorkers Directive

Description:Maximum number of worker threads to use per child process.
Syntax:H2MaxWorkers n
Context:server config
Status:Extension
Module:mod_http2

This directive sets the maximum number of worker threads to spawn per child process for HTTP/2 processing. If this directive is not used, mod_http2 will chose a value suitable for the mpm module loaded.

Example

H2MaxWorkers 20
top

H2MinWorkers Directive

Description:Minimal number of worker threads to use per child process.
Syntax:H2MinWorkers n
Context:server config
Status:Extension
Module:mod_http2

This directive sets the minimum number of worker threads to spawn per child process for HTTP/2 processing. If this directive is not used, mod_http2 will chose a value suitable for the mpm module loaded.

Example

H2MinWorkers 10
top

H2ModernTLSOnly Directive

Description:Require HTTP/2 connections to be "modern TLS" only
Syntax:H2ModernTLSOnly on|off
Default:H2ModernTLSOnly on
Context:server config, virtual host
Status:Extension
Module:mod_http2

This directive toggles the security checks on HTTP/2 connections in TLS mode (https:). This can be used server wide or for specific <VirtualHost>s.

The security checks require that the TSL protocol is at least TLSv1.2 and that none of the ciphers listed in RFC 7540, Appendix A is used. These checks will be extended once new security requirements come into place.

The name stems from the Security/Server Side TLS definitions at mozilla where "modern compatiblity" is defined. Mozilla Firefox and other browsers require modern compatiblity for HTTP/2 connections. As everything in OpSec, this is a moving target and can be expected to evolve in the future.

One purpose of having these checks in mod_http2 is to enforce this security level for all connections, not only those from browsers. The other purpose is to prevent the negotiation of HTTP/2 as a protocol should the requirements not be met.

Ultimately, the security of the TLS connection is determined by the server configuration directives for mod_ssl.

Example

H2ModernTLSOnly off
top

H2SerializeHeaders Directive

Description:Serialize Request/Response Processing Switch
Syntax:H2SerializeHeaders on|off
Default:H2SerializeHeaders off
Context:server config, virtual host
Status:Extension
Module:mod_http2

This directive toggles if HTTP/2 requests shall be serialized in HTTP/1.1 format for processing by httpd core or if received binary data shall be passed into the request_recs directly.

Serialization will lower performance, but gives more backward compatibility in case custom filters/hooks need it.

Example

H2SerializeHeaders on
top

H2SessionExtraFiles Directive

Description:Number of Extra File Handles
Syntax:H2SessionExtraFiles n
Default:H2SessionExtraFiles 5
Context:server config, virtual host
Status:Extension
Module:mod_http2

This directive sets maximum number of extra file handles a HTTP/2 session is allowed to use. A file handle is counted as extra when it is transfered from a h2 worker thread to the main HTTP/2 connection handling. This commonly happens when serving static files.

Depending on the processing model configured on the server, the number of connections times number of active streams may exceed the number of file handles for the process. On the other hand, converting every file into memory bytes early results in too many buffer writes. This option helps to mitigate that.

The number of file handles used by a server process is then in the order of:

(h2_connections * extra_files) + (h2_max_worker)

Example

H2SessionExtraFiles 10
top

H2StreamMaxMemSize Directive

Description:Maximum amount of output data buffered per stream.
Syntax:H2StreamMaxMemSize bytes
Default:H2StreamMaxMemSize 65536
Context:server config, virtual host
Status:Extension
Module:mod_http2

This directive sets the maximum number of outgoing data bytes buffered in memory for an active streams. This memory is not allocated per stream as such. Allocations are counted against this limit when they are about to be done. Stream processing freezes when the limit has been reached and will only continue when buffered data has been sent out to the client.

Example

H2StreamMaxMemSize 128000
top

H2TLSCoolDownSecs Directive

Description:
Syntax:H2TLSCoolDownSecs seconds
Default:H2TLSCoolDownSecs 1
Context:server config, virtual host
Status:Extension
Module:mod_http2

This directive sets the number of seconds of idle time on a TLS connection before the TLS write size falls back to small (~1300 bytes) length. This can be used server wide or for specific <VirtualHost>s.

See <H2TLSWarmUpSize> for a description of TLS warmup. H2TLSCoolDownSecs reflects the fact that connections may detoriate over time (and TCP flow adjusts) for idle connections as well. It is beneficial to overall performance to fall back to the pre-warmup phase after a number of seconds that no data has been sent.

In deployments where connections can be considered reliable, this timer can be disabled by setting it to 0.

The following example sets the seconds to zero, effectively disabling any cooldown. Warmed up TLS connections stay on maximum record size.

Example

H2TLSCoolDownSecs 0
top

H2TLSWarmUpSize Directive

Description:
Syntax:H2TLSWarmUpSize amount
Default:H2TLSWarmUpSize 1048576
Context:server config, virtual host
Status:Extension
Module:mod_http2

This directive sets the number of bytes to be sent in small TLS records (~1300 bytes) until doing maximum sized writes (16k) on https: HTTP/2 connections. This can be used server wide or for specific <VirtualHost>s.

Measurements by google performance labs show that best performance on TLS connections is reached, if initial record sizes stay below the MTU level, to allow a complete record to fit into an IP packet.

While TCP adjust its flow-control and window sizes, longer TLS records can get stuck in queues or get lost and need retransmission. This is of course true for all packets. TLS however needs the whole record in order to decrypt it. Any missing bytes at the end will stall usage of the received ones.

After a sufficient number of bytes have been send successfully, the TCP state of the connection is stable and maximum TLS record sizes (16 KB) can be used for optimal performance.

In deployments where servers are reached locally or over reliable connections only, the value might be decreased with 0 disabling any warmup phase alltogether.

The following example sets the size to zero, effectively disabling any warmup phase.

Example

H2TLSWarmUpSize 0
top

H2Upgrade Directive

Description:H2 Upgrade Protocol Switch
Syntax:H2Upgrade on|off
Default:H2Upgrade on for http:, off for https: requests
Context:server config, virtual host
Status:Extension
Module:mod_http2

This directive toggles the usage of the HTTP/1.1 Upgrade method for switching to HTTP/2. This should be used inside a <VirtualHost> section to enable Upgrades to HTTP/2 for that virtual host.

This method of switching protocols is defined in HTTP/1.1 and uses the "Upgrade" header (thus the name) to announce willingness to use another protocol. This may happen on any request of a HTTP/1.1 connection.

This method of protocol switching is enabled by default on cleartext (http:) connections and disabled on TLS (https:), as mandated by RFC 7540.

This mode only has an effect when h2 or h2c is enabled via the <Protocols>.

Example

H2Upgrade on
top

H2WindowSize Directive

Description:Size of Stream Window for upstream data.
Syntax:H2WindowSize bytes
Default:H2WindowSize 65536
Context:server config, virtual host
Status:Extension
Module:mod_http2

This directive sets the size of the window that is used for flow control from client to server and limits the amount of data the server has to buffer. The client will stop sending on a stream once the limit has been reached until the server announces more available space (as it has processed some of the data).

This limit affects only request bodies, not its meta data such as headers. Also, it has no effect on response bodies as the window size for those are managed by the clients.

Example

H2WindowSize 128000

Available Languages:  en 

top

Comments

Notice:
This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our mailing lists.