Update Nginx auf 1.13.1

This commit is contained in:
2017-06-10 15:31:44 +02:00
parent 4dba15c05e
commit 766d8e87e6
103 changed files with 4847 additions and 2573 deletions

View File

@@ -17,6 +17,8 @@ static ngx_int_t ngx_http_upstream_cache_get(ngx_http_request_t *r,
ngx_http_upstream_t *u, ngx_http_file_cache_t **cache);
static ngx_int_t ngx_http_upstream_cache_send(ngx_http_request_t *r,
ngx_http_upstream_t *u);
static ngx_int_t ngx_http_upstream_cache_background_update(
ngx_http_request_t *r, ngx_http_upstream_t *u);
static ngx_int_t ngx_http_upstream_cache_check_range(ngx_http_request_t *r,
ngx_http_upstream_t *u);
static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r,
@@ -162,6 +164,10 @@ static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_upstream_response_length_variable(
ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_upstream_header_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_upstream_cookie_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy);
static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd,
@@ -182,7 +188,7 @@ static ngx_int_t ngx_http_upstream_ssl_name(ngx_http_request_t *r,
#endif
ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = {
static ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = {
{ ngx_string("Status"),
ngx_http_upstream_process_header_line,
@@ -413,6 +419,12 @@ static ngx_http_variable_t ngx_http_upstream_vars[] = {
#endif
{ ngx_string("upstream_http_"), NULL, ngx_http_upstream_header_variable,
0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 },
{ ngx_string("upstream_cookie_"), NULL, ngx_http_upstream_cookie_variable,
0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 },
{ ngx_null_string, NULL, NULL, 0, 0, 0 }
};
@@ -424,6 +436,7 @@ static ngx_http_upstream_next_t ngx_http_upstream_next_errors[] = {
{ 504, NGX_HTTP_UPSTREAM_FT_HTTP_504 },
{ 403, NGX_HTTP_UPSTREAM_FT_HTTP_403 },
{ 404, NGX_HTTP_UPSTREAM_FT_HTTP_404 },
{ 429, NGX_HTTP_UPSTREAM_FT_HTTP_429 },
{ 0, 0 }
};
@@ -568,6 +581,10 @@ ngx_http_upstream_init_request(ngx_http_request_t *r)
rc = NGX_DECLINED;
r->cached = 0;
}
if (ngx_http_upstream_cache_background_update(r, u) != NGX_OK) {
rc = NGX_ERROR;
}
}
if (rc != NGX_DECLINED) {
@@ -859,9 +876,24 @@ ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
switch (rc) {
case NGX_HTTP_CACHE_STALE:
if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING)
|| c->stale_updating) && !r->background
&& u->conf->cache_background_update)
{
r->cache->background = 1;
u->cache_status = rc;
rc = NGX_OK;
}
break;
case NGX_HTTP_CACHE_UPDATING:
if (u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING) {
if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING)
|| c->stale_updating) && !r->background)
{
u->cache_status = rc;
rc = NGX_OK;
@@ -884,6 +916,9 @@ ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
case NGX_HTTP_CACHE_STALE:
c->valid_sec = 0;
c->updating_sec = 0;
c->error_sec = 0;
u->buffer.start = NULL;
u->cache_status = NGX_HTTP_CACHE_EXPIRED;
@@ -1030,6 +1065,30 @@ ngx_http_upstream_cache_send(ngx_http_request_t *r, ngx_http_upstream_t *u)
}
static ngx_int_t
ngx_http_upstream_cache_background_update(ngx_http_request_t *r,
ngx_http_upstream_t *u)
{
ngx_http_request_t *sr;
if (!r->cached || !r->cache->background) {
return NGX_OK;
}
if (ngx_http_subrequest(r, &r->uri, &r->args, &sr, NULL,
NGX_HTTP_SUBREQUEST_CLONE
|NGX_HTTP_SUBREQUEST_BACKGROUND)
!= NGX_OK)
{
return NGX_ERROR;
}
sr->header_only = 1;
return NGX_OK;
}
static ngx_int_t
ngx_http_upstream_cache_check_range(ngx_http_request_t *r,
ngx_http_upstream_t *u)
@@ -1174,6 +1233,11 @@ ngx_http_upstream_handler(ngx_event_t *ev)
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
"http upstream request: \"%V?%V\"", &r->uri, &r->args);
if (ev->delayed && ev->timedout) {
ev->delayed = 0;
ev->timedout = 0;
}
if (ev->write) {
u->write_event_handler(r, u);
@@ -1542,7 +1606,6 @@ static void
ngx_http_upstream_ssl_init_connection(ngx_http_request_t *r,
ngx_http_upstream_t *u, ngx_connection_t *c)
{
int tcp_nodelay;
ngx_int_t rc;
ngx_http_core_loc_conf_t *clcf;
@@ -1582,22 +1645,10 @@ ngx_http_upstream_ssl_init_connection(ngx_http_request_t *r,
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay");
tcp_nodelay = 1;
if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY,
(const void *) &tcp_nodelay, sizeof(int)) == -1)
{
ngx_connection_error(c, ngx_socket_errno,
"setsockopt(TCP_NODELAY) failed");
ngx_http_upstream_finalize_request(r, u,
if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) {
ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}
c->tcp_nodelay = NGX_TCP_NODELAY_SET;
return;
}
}
@@ -1950,7 +2001,6 @@ static ngx_int_t
ngx_http_upstream_send_request_body(ngx_http_request_t *r,
ngx_http_upstream_t *u, ngx_uint_t do_write)
{
int tcp_nodelay;
ngx_int_t rc;
ngx_chain_t *out, *cl, *ln;
ngx_connection_t *c;
@@ -1987,20 +2037,8 @@ ngx_http_upstream_send_request_body(ngx_http_request_t *r,
c = u->peer.connection;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay");
tcp_nodelay = 1;
if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY,
(const void *) &tcp_nodelay, sizeof(int)) == -1)
{
ngx_connection_error(c, ngx_socket_errno,
"setsockopt(TCP_NODELAY) failed");
return NGX_ERROR;
}
c->tcp_nodelay = NGX_TCP_NODELAY_SET;
if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) {
return NGX_ERROR;
}
r->read_event_handler = ngx_http_upstream_read_request_handler;
@@ -2330,7 +2368,7 @@ ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u)
#if (NGX_HTTP_CACHE)
if (u->cache_status == NGX_HTTP_CACHE_EXPIRED
&& (u->conf->cache_use_stale & un->mask))
&& ((u->conf->cache_use_stale & un->mask) || r->cache->stale_error))
{
ngx_int_t rc;
@@ -2354,14 +2392,17 @@ ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u)
&& u->cache_status == NGX_HTTP_CACHE_EXPIRED
&& u->conf->cache_revalidate)
{
time_t now, valid;
time_t now, valid, updating, error;
ngx_int_t rc;
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
"http upstream not modified");
now = ngx_time();
valid = r->cache->valid_sec;
updating = r->cache->updating_sec;
error = r->cache->error_sec;
rc = u->reinit_request(r);
@@ -2375,6 +2416,8 @@ ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u)
if (valid == 0) {
valid = r->cache->valid_sec;
updating = r->cache->updating_sec;
error = r->cache->error_sec;
}
if (valid == 0) {
@@ -2387,6 +2430,9 @@ ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u)
if (valid) {
r->cache->valid_sec = valid;
r->cache->updating_sec = updating;
r->cache->error_sec = error;
r->cache->date = now;
ngx_http_file_cache_update_header(r);
@@ -2750,7 +2796,6 @@ ngx_http_upstream_process_body_in_memory(ngx_http_request_t *r,
static void
ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
int tcp_nodelay;
ssize_t n;
ngx_int_t rc;
ngx_event_pipe_t *p;
@@ -2831,21 +2876,9 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
return;
}
if (clcf->tcp_nodelay && c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay");
tcp_nodelay = 1;
if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY,
(const void *) &tcp_nodelay, sizeof(int)) == -1)
{
ngx_connection_error(c, ngx_socket_errno,
"setsockopt(TCP_NODELAY) failed");
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
return;
}
c->tcp_nodelay = NGX_TCP_NODELAY_SET;
if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) {
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
return;
}
n = u->buffer.last - u->buffer.pos;
@@ -3104,7 +3137,6 @@ ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
static void
ngx_http_upstream_upgrade(ngx_http_request_t *r, ngx_http_upstream_t *u)
{
int tcp_nodelay;
ngx_connection_t *c;
ngx_http_core_loc_conf_t *clcf;
@@ -3122,37 +3154,15 @@ ngx_http_upstream_upgrade(ngx_http_request_t *r, ngx_http_upstream_t *u)
r->write_event_handler = ngx_http_upstream_upgraded_write_downstream;
if (clcf->tcp_nodelay) {
tcp_nodelay = 1;
if (c->tcp_nodelay == NGX_TCP_NODELAY_UNSET) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "tcp_nodelay");
if (setsockopt(c->fd, IPPROTO_TCP, TCP_NODELAY,
(const void *) &tcp_nodelay, sizeof(int)) == -1)
{
ngx_connection_error(c, ngx_socket_errno,
"setsockopt(TCP_NODELAY) failed");
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
return;
}
c->tcp_nodelay = NGX_TCP_NODELAY_SET;
if (ngx_tcp_nodelay(c) != NGX_OK) {
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
return;
}
if (u->peer.connection->tcp_nodelay == NGX_TCP_NODELAY_UNSET) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, u->peer.connection->log, 0,
"tcp_nodelay");
if (setsockopt(u->peer.connection->fd, IPPROTO_TCP, TCP_NODELAY,
(const void *) &tcp_nodelay, sizeof(int)) == -1)
{
ngx_connection_error(u->peer.connection, ngx_socket_errno,
"setsockopt(TCP_NODELAY) failed");
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
return;
}
u->peer.connection->tcp_nodelay = NGX_TCP_NODELAY_SET;
if (ngx_tcp_nodelay(u->peer.connection) != NGX_OK) {
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
return;
}
}
@@ -3670,9 +3680,19 @@ ngx_http_upstream_thread_event_handler(ngx_event_t *ev)
r->main->blocked--;
r->aio = 0;
r->write_event_handler(r);
if (r->done) {
/*
* trigger connection event handler if the subrequest was
* already finalized; this can happen if the handler is used
* for sendfile() in threads
*/
ngx_http_run_posted_requests(c);
c->write->handler(c->write);
} else {
r->write_event_handler(r);
ngx_http_run_posted_requests(c);
}
}
#endif
@@ -3720,31 +3740,9 @@ ngx_http_upstream_process_downstream(ngx_http_request_t *r)
if (wev->timedout) {
if (wev->delayed) {
wev->timedout = 0;
wev->delayed = 0;
if (!wev->ready) {
ngx_add_timer(wev, p->send_timeout);
if (ngx_handle_write_event(wev, p->send_lowat) != NGX_OK) {
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
}
return;
}
if (ngx_event_pipe(p, wev->write) == NGX_ABORT) {
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
return;
}
} else {
p->downstream_error = 1;
c->timedout = 1;
ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out");
}
p->downstream_error = 1;
c->timedout = 1;
ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out");
} else {
@@ -3789,30 +3787,8 @@ ngx_http_upstream_process_upstream(ngx_http_request_t *r,
if (rev->timedout) {
if (rev->delayed) {
rev->timedout = 0;
rev->delayed = 0;
if (!rev->ready) {
ngx_add_timer(rev, p->read_timeout);
if (ngx_handle_read_event(rev, 0) != NGX_OK) {
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
}
return;
}
if (ngx_event_pipe(p, 0) == NGX_ABORT) {
ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
return;
}
} else {
p->upstream_error = 1;
ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");
}
p->upstream_error = 1;
ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");
} else {
@@ -4089,6 +4065,10 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
status = NGX_HTTP_NOT_FOUND;
break;
case NGX_HTTP_UPSTREAM_FT_HTTP_429:
status = NGX_HTTP_TOO_MANY_REQUESTS;
break;
/*
* NGX_HTTP_UPSTREAM_FT_BUSY_LOCK and NGX_HTTP_UPSTREAM_FT_MAX_WAITING
* never reach here
@@ -4122,7 +4102,7 @@ ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
#if (NGX_HTTP_CACHE)
if (u->cache_status == NGX_HTTP_CACHE_EXPIRED
&& (u->conf->cache_use_stale & ft_type))
&& ((u->conf->cache_use_stale & ft_type) || r->cache->stale_error))
{
ngx_int_t rc;
@@ -4300,6 +4280,8 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r,
u->buffer.last = u->buffer.pos;
}
r->read_event_handler = ngx_http_block_reading;
if (rc == NGX_DECLINED) {
return;
}
@@ -4497,32 +4479,76 @@ ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
offset = 8;
}
if (p == NULL) {
return NGX_OK;
}
if (p) {
n = 0;
n = 0;
for (p += offset; p < last; p++) {
if (*p == ',' || *p == ';' || *p == ' ') {
break;
}
for (p += offset; p < last; p++) {
if (*p == ',' || *p == ';' || *p == ' ') {
break;
if (*p >= '0' && *p <= '9') {
n = n * 10 + *p - '0';
continue;
}
u->cacheable = 0;
return NGX_OK;
}
if (*p >= '0' && *p <= '9') {
n = n * 10 + *p - '0';
continue;
if (n == 0) {
u->cacheable = 0;
return NGX_OK;
}
u->cacheable = 0;
return NGX_OK;
r->cache->valid_sec = ngx_time() + n;
}
if (n == 0) {
u->cacheable = 0;
return NGX_OK;
p = ngx_strlcasestrn(start, last, (u_char *) "stale-while-revalidate=",
23 - 1);
if (p) {
n = 0;
for (p += 23; p < last; p++) {
if (*p == ',' || *p == ';' || *p == ' ') {
break;
}
if (*p >= '0' && *p <= '9') {
n = n * 10 + *p - '0';
continue;
}
u->cacheable = 0;
return NGX_OK;
}
r->cache->updating_sec = n;
r->cache->error_sec = n;
}
r->cache->valid_sec = ngx_time() + n;
p = ngx_strlcasestrn(start, last, (u_char *) "stale-if-error=", 15 - 1);
if (p) {
n = 0;
for (p += 15; p < last; p++) {
if (*p == ',' || *p == ';' || *p == ' ') {
break;
}
if (*p >= '0' && *p <= '9') {
n = n * 10 + *p - '0';
continue;
}
u->cacheable = 0;
return NGX_OK;
}
r->cache->error_sec = n;
}
}
#endif
@@ -4809,17 +4835,18 @@ ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r,
}
}
ph = ngx_array_push(pa);
if (ph == NULL) {
return NGX_ERROR;
}
ho = ngx_list_push(&r->headers_out.headers);
if (ho == NULL) {
return NGX_ERROR;
}
*ho = *h;
ph = ngx_array_push(pa);
if (ph == NULL) {
return NGX_ERROR;
}
*ph = ho;
return NGX_OK;
@@ -5391,7 +5418,7 @@ ngx_http_upstream_response_length_variable(ngx_http_request_t *r,
}
ngx_int_t
static ngx_int_t
ngx_http_upstream_header_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{
@@ -5406,7 +5433,7 @@ ngx_http_upstream_header_variable(ngx_http_request_t *r,
}
ngx_int_t
static ngx_int_t
ngx_http_upstream_cookie_variable(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{
@@ -5442,7 +5469,7 @@ ngx_http_upstream_cookie_variable(ngx_http_request_t *r,
#if (NGX_HTTP_CACHE)
ngx_int_t
static ngx_int_t
ngx_http_upstream_cache_status(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{