mirror of
https://github.com/nginx/nginx.git
synced 2024-12-13 02:39:00 +08:00
SNI: avoid surplus lookup of virtual server if SNI was used.
This commit is contained in:
parent
8c4fea1766
commit
f61612532c
@ -693,6 +693,13 @@ ngx_http_ssl_servername(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg)
|
|||||||
return SSL_TLSEXT_ERR_NOACK;
|
return SSL_TLSEXT_ERR_NOACK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hc->ssl_servername = ngx_palloc(c->pool, sizeof(ngx_str_t));
|
||||||
|
if (hc->ssl_servername == NULL) {
|
||||||
|
return SSL_TLSEXT_ERR_NOACK;
|
||||||
|
}
|
||||||
|
|
||||||
|
*hc->ssl_servername = host;
|
||||||
|
|
||||||
hc->conf_ctx = cscf->ctx;
|
hc->conf_ctx = cscf->ctx;
|
||||||
|
|
||||||
clcf = ngx_http_get_module_loc_conf(hc->conf_ctx, ngx_http_core_module);
|
clcf = ngx_http_get_module_loc_conf(hc->conf_ctx, ngx_http_core_module);
|
||||||
@ -1831,6 +1838,28 @@ ngx_http_set_virtual_server(ngx_http_request_t *r, ngx_str_t *host)
|
|||||||
|
|
||||||
hc = r->http_connection;
|
hc = r->http_connection;
|
||||||
|
|
||||||
|
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
|
||||||
|
|
||||||
|
if (hc->ssl_servername) {
|
||||||
|
if (hc->ssl_servername->len == host->len
|
||||||
|
&& ngx_strncmp(hc->ssl_servername->data,
|
||||||
|
host->data, host->len) == 0)
|
||||||
|
{
|
||||||
|
#if (NGX_PCRE)
|
||||||
|
if (hc->ssl_servername_regex
|
||||||
|
&& ngx_http_regex_exec(r, hc->ssl_servername_regex,
|
||||||
|
hc->ssl_servername) != NGX_OK)
|
||||||
|
{
|
||||||
|
ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
return NGX_ERROR;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return NGX_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
rc = ngx_http_find_virtual_server(r->connection,
|
rc = ngx_http_find_virtual_server(r->connection,
|
||||||
hc->addr_conf->virtual_names,
|
hc->addr_conf->virtual_names,
|
||||||
host, r, &cscf);
|
host, r, &cscf);
|
||||||
@ -1887,6 +1916,8 @@ ngx_http_find_virtual_server(ngx_connection_t *c,
|
|||||||
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
|
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
|
||||||
|
|
||||||
if (r == NULL) {
|
if (r == NULL) {
|
||||||
|
ngx_http_connection_t *hc;
|
||||||
|
|
||||||
for (i = 0; i < virtual_names->nregex; i++) {
|
for (i = 0; i < virtual_names->nregex; i++) {
|
||||||
|
|
||||||
n = ngx_regex_exec(sn[i].regex->regex, host, NULL, 0);
|
n = ngx_regex_exec(sn[i].regex->regex, host, NULL, 0);
|
||||||
@ -1896,6 +1927,9 @@ ngx_http_find_virtual_server(ngx_connection_t *c,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (n >= 0) {
|
if (n >= 0) {
|
||||||
|
hc = c->data;
|
||||||
|
hc->ssl_servername_regex = sn[i].regex;
|
||||||
|
|
||||||
*cscfp = sn[i].server;
|
*cscfp = sn[i].server;
|
||||||
return NGX_OK;
|
return NGX_OK;
|
||||||
}
|
}
|
||||||
|
@ -295,6 +295,13 @@ typedef struct {
|
|||||||
ngx_http_addr_conf_t *addr_conf;
|
ngx_http_addr_conf_t *addr_conf;
|
||||||
ngx_http_conf_ctx_t *conf_ctx;
|
ngx_http_conf_ctx_t *conf_ctx;
|
||||||
|
|
||||||
|
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
|
||||||
|
ngx_str_t *ssl_servername;
|
||||||
|
#if (NGX_PCRE)
|
||||||
|
ngx_http_regex_t *ssl_servername_regex;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
ngx_http_request_t *request;
|
ngx_http_request_t *request;
|
||||||
|
|
||||||
ngx_buf_t **busy;
|
ngx_buf_t **busy;
|
||||||
|
Loading…
Reference in New Issue
Block a user