HTTP/2: ngx_http_v2_proxy_module.

The module allows to use HTTP/2 protocol for proxying.
HTTP/2 proxying is enabled by specifying "proxy_http_version 2.0".

Example:

    server {
        listen 8000;

        location / {
            proxy_http_version 2.0;
            proxy_pass https://127.0.0.1:8443;
        }
    }

    server {
        listen 8443 ssl;
        http2 on;

        ssl_certificate certs/example.com.crt;
        ssl_certificate_key certs/example.com.key;

        location / {
            return 200 foo;
        }
    }
This commit is contained in:
Zhidao HONG 2025-07-15 15:35:39 +00:00
parent 40cd8f229c
commit 0c3897bb70
4 changed files with 3903 additions and 2 deletions

View File

@ -782,6 +782,17 @@ if [ $HTTP = YES ]; then
. auto/module
fi
if [ $HTTP_V2 = YES ]; then
ngx_module_name=ngx_http_v2_proxy_module
ngx_module_incs=
ngx_module_deps=
ngx_module_srcs=src/http/v2/ngx_http_v2_proxy_module.c
ngx_module_libs=
ngx_module_link=$HTTP_V2
. auto/module
fi
if [ $HTTP_PERL != NO ]; then
ngx_module_name=ngx_http_perl_module
ngx_module_incs=src/http/modules/perl

View File

@ -165,6 +165,9 @@ static ngx_conf_post_t ngx_http_proxy_ssl_conf_command_post =
static ngx_conf_enum_t ngx_http_proxy_http_version[] = {
{ ngx_string("1.0"), NGX_HTTP_VERSION_10 },
{ ngx_string("1.1"), NGX_HTTP_VERSION_11 },
#if (NGX_HTTP_V2)
{ ngx_string("2.0"), NGX_HTTP_VERSION_20 },
#endif
{ ngx_null_string, 0 }
};
@ -838,6 +841,14 @@ ngx_http_proxy_handler(ngx_http_request_t *r)
ngx_http_proxy_main_conf_t *pmcf;
#endif
plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
#if (NGX_HTTP_V2)
if (plcf->http_version == NGX_HTTP_VERSION_20) {
return ngx_http_v2_proxy_handler(r);
}
#endif
if (ngx_http_upstream_create(r) != NGX_OK) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}
@ -851,8 +862,6 @@ ngx_http_proxy_handler(ngx_http_request_t *r)
ngx_http_set_ctx(r, ctx, ngx_http_proxy_module);
plcf = ngx_http_get_module_loc_conf(r, ngx_http_proxy_module);
u = r->upstream;
if (plcf->proxy_lengths == NULL) {

View File

@ -416,6 +416,8 @@ ngx_int_t ngx_http_v2_table_size(ngx_http_v2_connection_t *h2c, size_t size);
u_char *ngx_http_v2_string_encode(u_char *dst, u_char *src, size_t len,
u_char *tmp, ngx_uint_t lower);
ngx_int_t ngx_http_v2_proxy_handler(ngx_http_request_t *r);
extern ngx_module_t ngx_http_v2_module;

File diff suppressed because it is too large Load Diff