<!-- review: finished -->

<a id="stream-ssl-preread"></a>

# SSL Preread

Enables extracting information from the
[ClientHello](https://datatracker.ietf.org/doc/html/rfc5246#section-7.4.1.2)
message without terminating TLS,
such as the server name requested via
[SNI](https://datatracker.ietf.org/doc/html/rfc6066#section-3)
or protocols advertised in
[ALPN](https://datatracker.ietf.org/doc/html/rfc7301).

When [building from the 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‑stream_ssl_preread_module`
[build option](https://en.angie.software//angie/docs/installation/sourcebuild.md#configure).

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

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

## Configuration Example

<a id="selecting-an-upstream-by-server-name"></a>

### Selecting an upstream by server name

```nginx
map $ssl_preread_server_name $name {
    backend.example.com      backend;
    default                  backend2;
}

upstream backend {
    server 192.168.0.1:12345;
    server 192.168.0.2:12345;
}

upstream backend2 {
    server 192.168.0.3:12345;
    server 192.168.0.4:12345;
}

server {
    listen      12346;
    proxy_pass  $name;
    ssl_preread on;
}
```

<a id="selecting-a-server-by-protocol"></a>

### Selecting a server by protocol

```nginx
map $ssl_preread_alpn_protocols $proxy {
    ~\bh2\b           127.0.0.1:8001;
    ~\bhttp/1.1\b     127.0.0.1:8002;
    ~\bxmpp-client\b  127.0.0.1:8003;
}

server {
    listen      9000;
    proxy_pass  $proxy;
    ssl_preread on;
}
```

<a id="selecting-a-server-by-ssl-protocol-version"></a>

### Selecting a server by SSL protocol version

```nginx
map $ssl_preread_protocol $upstream {
    ""        ssh.example.com:22;
    "TLSv1.2" new.example.com:443;
    default   tls.example.com:443;
}

# ssh and https at the same port
server {
    listen      192.168.0.1:443;
    proxy_pass  $upstream;
    ssl_preread on;
}
```

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

## Directives

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

<a id="s-ssl-preread"></a>

### ssl_preread

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

Enables extracting information from the ClientHello message at the
[preread](https://en.angie.software//angie/docs/configuration/processing.md#stream-sessions) phase.

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

## Built-in Variables

<a id="v-ssl-preread-protocol"></a>

### `$ssl_preread_protocol`

Highest SSL protocol version supported by the client.

<a id="v-ssl-preread-server-name"></a>

### `$ssl_preread_server_name`

Server name requested via SNI.

<a id="v-ssl-preread-alpn-protocols"></a>

### `$ssl_preread_alpn_protocols`

List of protocols advertised by the client through ALPN.
The values are comma separated.
