<!-- review: finished -->

<a id="http-v2"></a>

# HTTP/2

Provides support for [HTTP/2](https://datatracker.ietf.org/doc/html/rfc9113).

When [building from source code](https://en.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild),
this module isn't built by default;
it should be enabled with the
`‑‑with‑http_v2_module`
[build option](https://en.angie.software//angie/docs/installation/sourcebuild.md#configure).

In packages and images from [our repositories](https://en.angie.software//angie/docs/installation/index.md#install-packages),
the module is included in the build.

<a id="configuration-example-49"></a>

## Configuration Example

```nginx
server {
    listen 443 ssl;

    http2 on;

    ssl_certificate server.crt;
    ssl_certificate_key server.key;
}
```

#### NOTE
Note that accepting HTTP/2 connections over TLS requires the "Application-Layer Protocol Negotiation" (ALPN) TLS extension support, which is available since [OpenSSL](http://www.openssl.org/) version 1.0.2.

If the [ssl_prefer_server_ciphers](https://en.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-prefer-server-ciphers) directive is set to the value "on", the [ciphers](https://en.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-ciphers) should be configured to comply with the [RFC 9113, Appendix A](https://datatracker.ietf.org/doc/html/rfc9113#appendix-A) blacklist and be supported by clients.

<a id="directives-52"></a>

## Directives

<a id="index-0"></a>

<a id="http2"></a>

### http2

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2` `on` | `off`;   |
|------------------------------------------------------------------------------------------|-------------------------|
| Default                                                                                  | `http2 off;`            |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server            |

Enables the [HTTP/2](https://datatracker.ietf.org/doc/html/rfc9113) protocol.

<a id="index-1"></a>

<a id="http2-body-preread-size"></a>

### http2_body_preread_size

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2_body_preread_size` size;   |
|------------------------------------------------------------------------------------------|-----------------------------------|
| Default                                                                                  | —                                 |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                      |

Sets the size of the buffer per each request in which the request body may be saved before it is started to be processed.

<a id="index-2"></a>

<a id="http2-chunk-size"></a>

### http2_chunk_size

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2_chunk_size` size;   |
|------------------------------------------------------------------------------------------|----------------------------|
| Default                                                                                  | `http2_chunk_size 8k;`     |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location     |

Sets the maximum size of chunks into which the response body is sliced. A too low value results in higher overhead. A too high value impairs prioritization due to [head-of-line blocking](http://en.wikipedia.org/wiki/Head-of-line_blocking).

<a id="index-3"></a>

<a id="http2-max-concurrent-pushes"></a>

### http2_max_concurrent_pushes

#### Deprecated
Deprecated since version 1.2.0.

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2_max_concurrent_pushes` number;   |
|------------------------------------------------------------------------------------------|-----------------------------------------|
| Default                                                                                  | `http2_max_concurrent_pushes 10;`       |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                            |

Limits the maximum number of concurrent [push](#http2-push) requests in a connection.

<a id="index-4"></a>

<a id="http2-max-concurrent-streams"></a>

### http2_max_concurrent_streams

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2_max_concurrent_streams` number;   |
|------------------------------------------------------------------------------------------|------------------------------------------|
| Default                                                                                  | `http2_max_concurrent_streams 128;`      |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                             |

Sets the maximum number of concurrent HTTP/2 streams in a connection.

<a id="index-5"></a>

<a id="http2-push"></a>

### http2_push

#### Deprecated
Deprecated since version 1.2.0.

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2_push` uri | `off`;   |
|------------------------------------------------------------------------------------------|-----------------------------|
| Default                                                                                  | `http2_push off;`           |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

Preemptively sends ([pushes](https://datatracker.ietf.org/doc/html/rfc9113#name-server-push)) a request to the specified uri along with the response to the original request. Only relative URIs with absolute path will be processed, for example:

```nginx
http2_push /static/css/main.css;
```

The `uri` value can contain variables.

Several http2_push directives can be specified on the same configuration level. The `off` parameter cancels the effect of the http2_push directives inherited from the previous configuration level.

<a id="index-6"></a>

<a id="http2-push-preload"></a>

### http2_push_preload

#### Deprecated
Deprecated since version 1.2.0.

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2_push_preload` `on` | `off`;   |
|------------------------------------------------------------------------------------------|--------------------------------------|
| Default                                                                                  | `http2_push_preload off;`            |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

Enables automatic conversion of [preload links](https://www.w3.org/TR/preload/#server-push-http-2) specified in the "Link" response header fields into [push](https://datatracker.ietf.org/doc/html/rfc9113#name-server-push) requests.

<a id="index-7"></a>

<a id="http2-recv-buffer-size"></a>

### http2_recv_buffer_size

| [Syntax](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2_recv_buffer_size` size;   |
|------------------------------------------------------------------------------------------|----------------------------------|
| Default                                                                                  | `http2_recv_buffer_size 256k;`   |
| [Context](https://en.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                             |

Sets the size of the per [worker](https://en.angie.software//angie/docs/configuration/modules/core.md#worker-processes) input buffer.

<a id="built-in-variables-17"></a>

## Built-in Variables

The http_v2 module supports the following built-in variables:

<a id="v-http2"></a>

### `$http2`

negotiated protocol identifier:

| `h2`   | for HTTP/2 over TLS           |
|--------|-------------------------------|
| `h2c`  | for HTTP/2 over cleartext TCP |
| `""`   | an empty string otherwise     |
