@@ -161,6 +161,9 @@ static ngx_conf_post_t ngx_http_proxy_ssl_conf_command_post =
161
161
static ngx_conf_enum_t ngx_http_proxy_http_version [] = {
162
162
{ ngx_string ("1.0" ), NGX_HTTP_VERSION_10 },
163
163
{ ngx_string ("1.1" ), NGX_HTTP_VERSION_11 },
164
+ #if (NGX_HTTP_V2 )
165
+ { ngx_string ("2.0" ), NGX_HTTP_VERSION_20 },
166
+ #endif
164
167
{ ngx_null_string , 0 }
165
168
};
166
169
@@ -830,6 +833,14 @@ ngx_http_proxy_handler(ngx_http_request_t *r)
830
833
ngx_http_proxy_main_conf_t * pmcf ;
831
834
#endif
832
835
836
+ plcf = ngx_http_get_module_loc_conf (r , ngx_http_proxy_module );
837
+
838
+ #if (NGX_HTTP_V2 )
839
+ if (plcf -> http_version == NGX_HTTP_VERSION_20 ) {
840
+ return ngx_http_v2_proxy_handler (r );
841
+ }
842
+ #endif
843
+
833
844
if (ngx_http_upstream_create (r ) != NGX_OK ) {
834
845
return NGX_HTTP_INTERNAL_SERVER_ERROR ;
835
846
}
@@ -841,8 +852,6 @@ ngx_http_proxy_handler(ngx_http_request_t *r)
841
852
842
853
ngx_http_set_ctx (r , ctx , ngx_http_proxy_module );
843
854
844
- plcf = ngx_http_get_module_loc_conf (r , ngx_http_proxy_module );
845
-
846
855
u = r -> upstream ;
847
856
848
857
if (plcf -> proxy_lengths == NULL ) {
@@ -3456,6 +3465,8 @@ ngx_http_proxy_create_loc_conf(ngx_conf_t *cf)
3456
3465
* conf->ssl_ciphers = { 0, NULL };
3457
3466
* conf->ssl_trusted_certificate = { 0, NULL };
3458
3467
* conf->ssl_crl = { 0, NULL };
3468
+ * conf->host = { 0, NULL };
3469
+ * conf->host_set = 0;
3459
3470
*/
3460
3471
3461
3472
conf -> upstream .store = NGX_CONF_UNSET ;
@@ -3980,6 +3991,9 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
3980
3991
3981
3992
#if (NGX_HTTP_SSL )
3982
3993
conf -> ssl = prev -> ssl ;
3994
+ #endif
3995
+ #if (NGX_HTTP_SSL )
3996
+ conf -> host = prev -> host ;
3983
3997
#endif
3984
3998
}
3985
3999
@@ -4019,6 +4033,9 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
4019
4033
conf -> headers = prev -> headers ;
4020
4034
#if (NGX_HTTP_CACHE )
4021
4035
conf -> headers_cache = prev -> headers_cache ;
4036
+ #endif
4037
+ #if (NGX_HTTP_V2 )
4038
+ conf -> host_set = prev -> host_set ;
4022
4039
#endif
4023
4040
}
4024
4041
@@ -4051,6 +4068,9 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
4051
4068
prev -> headers = conf -> headers ;
4052
4069
#if (NGX_HTTP_CACHE )
4053
4070
prev -> headers_cache = conf -> headers_cache ;
4071
+ #endif
4072
+ #if (NGX_HTTP_V2 )
4073
+ conf -> host_set = prev -> host_set ;
4054
4074
#endif
4055
4075
}
4056
4076
@@ -4104,6 +4124,14 @@ ngx_http_proxy_init_headers(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *conf,
4104
4124
src = conf -> headers_source -> elts ;
4105
4125
for (i = 0 ; i < conf -> headers_source -> nelts ; i ++ ) {
4106
4126
4127
+ #if (NGX_HTTP_V2 )
4128
+ if (src [i ].key .len == 4
4129
+ && ngx_strncasecmp (src [i ].key .data , (u_char * ) "Host" , 4 ) == 0 )
4130
+ {
4131
+ conf -> host_set = 1 ;
4132
+ }
4133
+ #endif
4134
+
4107
4135
s = ngx_array_push (& headers_merged );
4108
4136
if (s == NULL ) {
4109
4137
return NGX_ERROR ;
@@ -4343,6 +4371,27 @@ ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
4343
4371
4344
4372
plcf -> url = * url ;
4345
4373
4374
+ #if (NGX_HTTP_V2 )
4375
+
4376
+ if (plcf -> http_version == NGX_HTTP_VERSION_20 ) {
4377
+
4378
+ if (u .family != AF_UNIX ) {
4379
+
4380
+ if (u .no_port ) {
4381
+ plcf -> host = u .host ;
4382
+
4383
+ } else {
4384
+ plcf -> host .len = u .host .len + 1 + u .port_text .len ;
4385
+ plcf -> host .data = u .host .data ;
4386
+ }
4387
+
4388
+ } else {
4389
+ ngx_str_set (& plcf -> host , "localhost" );
4390
+ }
4391
+ }
4392
+
4393
+ #endif
4394
+
4346
4395
return NGX_CONF_OK ;
4347
4396
}
4348
4397
@@ -5274,6 +5323,21 @@ ngx_http_proxy_set_ssl(ngx_conf_t *cf, ngx_http_proxy_loc_conf_t *plcf)
5274
5323
return NGX_ERROR ;
5275
5324
}
5276
5325
5326
+ #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
5327
+
5328
+ if (plcf -> http_version == NGX_HTTP_VERSION_20 ) {
5329
+ if (SSL_CTX_set_alpn_protos (plcf -> upstream .ssl -> ctx ,
5330
+ (u_char * ) "\x02h2" , 3 )
5331
+ != 0 )
5332
+ {
5333
+ ngx_ssl_error (NGX_LOG_EMERG , cf -> log , 0 ,
5334
+ "SSL_CTX_set_alpn_protos() failed" );
5335
+ return NGX_ERROR ;
5336
+ }
5337
+ }
5338
+
5339
+ #endif
5340
+
5277
5341
if (ngx_ssl_conf_commands (cf , plcf -> upstream .ssl , plcf -> ssl_conf_commands )
5278
5342
!= NGX_OK )
5279
5343
{
0 commit comments