]> git.kaiwu.me - nginx.git/commitdiff
SNI: reuse selected configuration for all requests in a connection.
authorValentin Bartenev <vbart@nginx.com>
Wed, 27 Feb 2013 17:12:48 +0000 (17:12 +0000)
committerValentin Bartenev <vbart@nginx.com>
Wed, 27 Feb 2013 17:12:48 +0000 (17:12 +0000)
Previously, only the first request in a connection was assigned the
configuration selected by SNI.  All subsequent requests initially
used the default server's configuration, ignoring SNI, which was
wrong.

Now all subsequent requests in a connection will initially use the
configuration selected by SNI.  This is done by storing a pointer
to configuration in http connection object.  It points to default
server's configuration initially, but changed upon receipt of SNI.

(The request's configuration can be further refined when parsing
the request line and Host: header.)

This change was not made specific to SNI as it also allows slightly
faster access to configuration without the request object.

src/http/ngx_http.h
src/http/ngx_http_request.c
src/http/ngx_http_request.h

index f974081ea129ad11e672ecf017bf76948aa04c17..bf70c16a843518a1346cb67152503e1f9682df89 100644 (file)
@@ -27,11 +27,11 @@ typedef u_char *(*ngx_http_log_handler_pt)(ngx_http_request_t *r,
 
 
 #include <ngx_http_variables.h>
+#include <ngx_http_config.h>
 #include <ngx_http_request.h>
 #include <ngx_http_script.h>
 #include <ngx_http_upstream.h>
 #include <ngx_http_upstream_round_robin.h>
-#include <ngx_http_config.h>
 #include <ngx_http_busy_lock.h>
 #include <ngx_http_core_module.h>
 
index cab1f526254190d147ee21199794065d87c09585..93a519b7747bb08b5042337275005f6c1df25750 100644 (file)
@@ -292,6 +292,9 @@ ngx_http_init_connection(ngx_connection_t *c)
         }
     }
 
+    /* the default server configuration for the address:port */
+    hc->conf_ctx = hc->addr_conf->default_server->ctx;
+
     ctx = ngx_palloc(c->pool, sizeof(ngx_http_log_ctx_t));
     if (ctx == NULL) {
         ngx_http_close_connection(c);
@@ -399,12 +402,9 @@ ngx_http_init_request(ngx_event_t *rev)
 
     r->connection = c;
 
-    /* the default server configuration for the address:port */
-    cscf = hc->addr_conf->default_server;
-
-    r->main_conf = cscf->ctx->main_conf;
-    r->srv_conf = cscf->ctx->srv_conf;
-    r->loc_conf = cscf->ctx->loc_conf;
+    r->main_conf = hc->conf_ctx->main_conf;
+    r->srv_conf = hc->conf_ctx->srv_conf;
+    r->loc_conf = hc->conf_ctx->loc_conf;
 
     rev->handler = ngx_http_process_request_line;
     r->read_event_handler = ngx_http_block_reading;
@@ -449,6 +449,8 @@ ngx_http_init_request(ngx_event_t *rev)
 
     ngx_http_set_connection_log(r->connection, clcf->error_log);
 
+    cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
+
     if (c->buffer == NULL) {
         c->buffer = ngx_create_temp_buf(c->pool,
                                         cscf->client_header_buffer_size);
@@ -689,6 +691,8 @@ ngx_http_ssl_servername(ngx_ssl_conn_t *ssl_conn, int *ad, void *arg)
         return SSL_TLSEXT_ERR_NOACK;
     }
 
+    hc->conf_ctx = cscf->ctx;
+
     r->srv_conf = cscf->ctx->srv_conf;
     r->loc_conf = cscf->ctx->loc_conf;
 
index 7ceea62255f9b53a46312ba17cfbdd40b4309674..a2df0c6f29e1e25ae81371df03d8158eb3e7b326 100644 (file)
@@ -293,6 +293,7 @@ typedef struct ngx_http_addr_conf_s  ngx_http_addr_conf_t;
 
 typedef struct {
     ngx_http_addr_conf_t             *addr_conf;
+    ngx_http_conf_ctx_t              *conf_ctx;
 
     ngx_http_request_t               *request;