summaryrefslogtreecommitdiffhomepage
path: root/src/http/ngx_http_upstream.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2017-03-06Added missing "static" specifiers found by gcc -Wtraditional.Ruslan Ermilov1-1/+1
2017-03-02Added missing static specifiers.Eran Kornblau1-1/+1
2017-02-10Upstream: read handler cleared on upstream finalization.Maxim Dounin1-0/+2
With "proxy_ignore_client_abort off" (the default), upstream module changes r->read_event_handler to ngx_http_upstream_rd_check_broken_connection(). If the handler is not cleared during upstream finalization, it can be triggered later, causing unexpected effects, if, for example, a request was redirected to a different location using error_page or X-Accel-Redirect. In particular, it makes "proxy_ignore_client_abort on" non-working after a redirection in a configuration like this: location = / { error_page 502 = /error; proxy_pass http://127.0.0.1:8082; } location /error { proxy_pass http://127.0.0.1:8083; proxy_ignore_client_abort on; } It is also known to cause segmentation faults with aio used, see http://mailman.nginx.org/pipermail/nginx-ru/2015-August/056570.html. Fix is to explicitly set r->read_event_handler to ngx_http_block_reading() during upstream finalization, similar to how it is done in the request body reading code and in the limit_req module.
2017-02-10Upstream: proxy_cache_background_update and friends.Roman Arutyunyan1-2/+45
The directives enable cache updates in subrequests.
2016-12-22Cache: support for stale-while-revalidate and stale-if-error.Roman Arutyunyan1-20/+77
Previously, there was no way to enable the proxy_cache_use_stale behavior by reading the backend response. Now, stale-while-revalidate and stale-if-error Cache-Control extensions (RFC 5861) are supported. They specify, how long a stale response can be used when a cache entry is being updated, or in case of an error.
2017-01-31Variables: generic prefix variables.Dmitry Volyntsev1-2/+12
2017-01-20Upstream: fixed cache corruption and socket leaks with aio_write.Maxim Dounin1-0/+15
The ngx_event_pipe() function wasn't called on write events with wev->delayed set. As a result, threaded writing results weren't properly collected in ngx_event_pipe_write_to_downstream() when a write event was triggered for a completed write. Further, this wasn't detected, as p->aio was reset by a thread completion handler, and results were later collected in ngx_event_pipe_read_upstream() instead of scheduling a new write of additional data. If this happened on the last reading from an upstream, last part of the response was never written to the cache file. Similar problems might also happen in case of timeouts when writing to client, as this also results in ngx_event_pipe() not being called on write events. In this scenario socket leaks were observed. Fix is to check if p->writing is set in ngx_event_pipe_read_upstream(), and therefore collect results of previous write operations in case of read events as well, similar to how we do so in ngx_event_pipe_write_downstream(). This is enough to fix the wev->delayed case. Additionally, we now call ngx_event_pipe() from ngx_http_upstream_process_request() if there are uncollected write operations (p->writing and !p->aio). This also fixes the wev->timedout case.
2016-12-22Fixed missing "Location" field with some relative redirects.Ruslan Ermilov1-2/+2
Relative redirects did not work with directory redirects and auto redirects issued by nginx.
2016-11-14Upstream: handling of upstream SSL handshake timeouts.Maxim Dounin1-0/+7
Previously SSL handshake timeouts were not properly logged, and resulted in 502 errors instead of 504 (ticket #1126).
2016-11-03Cache: prefix-based temporary files.Maxim Dounin1-2/+3
On Linux, the rename syscall can be slow due to a global file system lock, acquired for the entire rename operation, unless both old and new files are in the same directory. To address this temporary files are now created in the same directory as the expected resulting cache file when using the "use_temp_path=off" parameter. This change mostly reverts 99639bfdfa2a and 3281de8142f5, restoring the behaviour as of a9138c35120d (with minor changes).
2016-11-03Upstream: avoid holding a cache node with upgraded connections.Maxim Dounin1-0/+17
Holding a cache node lock doesn't make sense as we can't use caching anyway, and results in "ignore long locked inactive cache entry" alerts if a node is locked for a long time. The same is done for unbuffered connections, as they can be alive for a long time as well.
2016-11-02Cache: proxy_cache_max_range_offset and friends.Dmitry Volyntsev1-0/+55
It configures a threshold in bytes, above which client range requests are not cached. In such a case the client's Range header is passed directly to a proxied server.
2016-10-17Upstream: removed ngx_http_upstream_srv_conf_t.default_port.Ruslan Ermilov1-2/+0
This is an API change.
2016-10-17Upstream: don't consider default_port when matching upstreams.Ruslan Ermilov1-6/+0
The only thing that default_port comparison did in the current code is prevented implicit upstreams to the same address/port from being aliased for http and https, e.g.: proxy_pass http://10.0.0.1:12345; proxy_pass https://10.0.0.1:12345; This is inconsistent because it doesn't work for a similar case with uswgi_pass: uwsgi_pass uwsgi://10.0.0.1:12345; uwsgi_pass suwsgi://10.0.0.1:12345; or with an explicit upstream: upstream u { server 10.0.0.1:12345; } proxy_pass http://u; proxy_pass https://u; Before c9059bd5445b, default_port comparison was needed to differentiate implicit upstreams in proxy_pass http://example.com; and proxy_pass https://example.com; as u->port was not set.
2016-10-17Upstream: consistently initialize explicit upstreams.Ruslan Ermilov1-0/+2
When an upstream{} block follows a proxy_pass reference to it, such an upstream inherited port and default_port settings from proxy_pass. This was different from when they came in another order (see ticket #1059). Explicit upstreams should not have port and default_port in any case. This fixes the following case: server { location / { proxy_pass http://u; } ... } upstream u { server 127.0.0.1; } server { location / { proxy_pass https://u; } ... } but not the following: server { location / { proxy_pass http://u; } ... } server { location / { proxy_pass https://u; } ... } upstream u { server 127.0.0.1; }
2016-10-31Upstream: do not unnecessarily create per-request upstreams.Ruslan Ermilov1-17/+17
If proxy_pass (and friends) with variables evaluates an upstream specified with literal address, nginx always created a per-request upstream. Now, if there's a matching upstream specified in the configuration (either implicit or explicit), it will be used instead.
2016-10-19SSL: compatibility with BoringSSL.Maxim Dounin1-1/+4
BoringSSL changed SSL_set_tlsext_host_name() to be a real function with a (const char *) argument, so it now triggers a warning due to conversion from (u_char *). Added an explicit cast to silence the warning. Prodded by Piotr Sikora, Alessandro Ghedini.
2016-10-14Upstream: hide_headers_hash handling at http level.Maxim Dounin1-1/+17
When headers to hide are set at the "http" level and not redefined in a server block, we now preserve compiled headers hash into the "http" section configuration to inherit this hash to all servers.
2016-10-14Upstream: hide_headers_hash inherited regardless of cache settings.Maxim Dounin1-6/+1
Dependency on cache settings existed prior to 2728c4e4a9ae (0.8.44) as Set-Cookie header was automatically hidden from responses when using cache. This is no longer the case, and hide_headers_hash can be safely inherited regardless of cache settings.
2016-09-22Upstream: max_conns.Ruslan Ermilov1-1/+19
2016-09-22Upstream: introduced u->upstream.Maxim Dounin1-0/+2
It holds upstream{} block configuration, including ones selected via run-time lookup using variables.
2016-09-20Fixed log levels of configuration parsing errors.Valentin Bartenev1-2/+2
All the errors that prevent loading configuration must be printed on the "emerg" log level. Previously, nginx might silently fail to load configuration in some cases as the default log level is "error".
2016-08-10Upstream: the $upstream_bytes_received variable.Vladimir Homutov1-1/+21
Unlike $upstream_response_length that only counts the body size, the new variable also counts the size of response header and data received after switching protocols when proxying WebSockets.
2016-06-20Upstream: support for port in proxy_bind and friends.Roman Arutyunyan1-2/+3
2016-05-13Improved EPOLLRDHUP handling.Valentin Bartenev1-1/+5
When it's known that the kernel supports EPOLLRDHUP, there is no need in additional recv() call to get EOF or error when the flag is absent in the event generated by the kernel. A special runtime test is done at startup to detect if EPOLLRDHUP is actually supported by the kernel because epoll_ctl() silently ignores unknown flags. With this knowledge it's now possible to drop the "ready" flag for partial read. Previously, the "ready" flag was kept until the recv() returned EOF or error. In particular, this change allows the lingering close heuristics (which relies on the "ready" flag state) to actually work on Linux, and not wait for more data in most cases. The "available" flag is now used in the read event with the semantics similar to the corresponding counter in kqueue.
2015-12-18Upstream: the "transparent" parameter of proxy_bind and friends.Roman Arutyunyan1-1/+21
This parameter lets binding the proxy connection to a non-local address. Upstream will see the connection as coming from that address. When used with $remote_addr, upstream will accept the connection from real client address. Example: proxy_bind $remote_addr transparent;
2016-04-13Upstream: prepared proxy_bind to accept parameters.Roman Arutyunyan1-38/+44
In addition, errors occurred while setting bind address are no longer ignored.
2016-03-30Style.Ruslan Ermilov1-12/+12
2016-03-28Upstream: proxy_next_upstream non_idempotent.Maxim Dounin1-1/+7
By default, requests with non-idempotent methods (POST, LOCK, PATCH) are no longer retried in case of errors if a request was already sent to a backend. Previous behaviour can be restored by using "proxy_next_upstream ... non_idempotent".
2016-03-28Upstream: cached connections now tested against next_upstream.Maxim Dounin1-49/+42
Much like normal connections, cached connections are now tested against u->conf->next_upstream, and u->state->status is now always set. This allows to disable additional tries even with upstream keepalive by using "proxy_next_upstream off".
2016-03-18Threads: writing via threads pools in event pipe.Maxim Dounin1-1/+116
The "aio_write" directive is introduced, which enables use of aio for writing. Currently it is meaningful only with "aio threads". Note that aio operations can be done by both event pipe and output chain, so proper mapping between r->aio and p->aio is provided when calling ngx_event_pipe() and in output filter. In collaboration with Valentin Bartenev.
2016-03-16Style.Ruslan Ermilov1-4/+4
2016-03-08Upstream: avoid closing client connection in edge case.Justin Li1-0/+5
If proxy_cache is enabled, and proxy_no_cache tests true, it was previously possible for the client connection to be closed after a 304. The fix is to recheck r->header_only after the final cacheability is determined, and end the request if no longer cacheable. Example configuration: proxy_cache foo; proxy_cache_bypass 1; proxy_no_cache 1; If a client sends If-None-Match, and the upstream server returns 200 with a matching ETag, no body should be returned to the client. At the start of ngx_http_upstream_send_response proxy_no_cache is not yet tested, thus cacheable is still 1 and downstream_error is set. However, by the time the downstream_error check is done in process_request, proxy_no_cache has been tested and cacheable is set to 0. The client connection is then closed, regardless of keepalive.
2016-03-10Upstream: fixed "zero size buf" alerts with cache (ticket #918).Maxim Dounin1-1/+2
If caching was used, "zero size buf in output" alerts might appear in logs if a client prematurely closed connection. Alerts appeared in the following situation: - writing to client returned an error, so event pipe drained all busy buffers leaving body output filters in an invalid state; - when upstream response was fully received, ngx_http_upstream_finalize_request() tried to flush all pending data. Fix is to avoid flushing body if p->downstream_error is set.
2016-02-04Dynamic modules: changed ngx_modules to cycle->modules.Maxim Dounin1-5/+5
2016-01-11Upstream: fixed changing method on X-Accel-Redirect.Maxim Dounin1-0/+1
Previously, only r->method was changed, resulting in handling of a request as GET within nginx itself, but not in requests to proxied servers. See http://mailman.nginx.org/pipermail/nginx/2015-December/049518.html.
2015-12-17Upstream: don't keep connections on early responses (ticket #669).Maxim Dounin1-0/+3
2015-12-09Fixed fastcgi_pass with UNIX socket and variables (ticket #855).Ruslan Ermilov1-1/+3
This was broken in a93345ee8f52 (1.9.8).
2015-12-07Upstream: fill r->headers_out.content_range from upstream response.Roman Arutyunyan1-0/+5
2015-12-02Style.Maxim Dounin1-1/+1
2015-11-06Style: unified request method checks.Ruslan Ermilov1-1/+1
2015-11-21Upstream: fixed "no port" detection in evaluated upstreams.Ruslan Ermilov1-2/+10
If an upstream with variables evaluated to address without a port, then instead of a "no port in upstream" error an attempt was made to connect() which failed with EADDRNOTAVAIL.
2015-11-11Upstream: proxy_cache_convert_head directive.Roman Arutyunyan1-1/+1
The directive toggles conversion of HEAD to GET for cacheable proxy requests. When disabled, $request_method must be added to cache key for consistency. By default, HEAD is converted to GET as before.
2015-09-11The HTTP/2 implementation (RFC 7240, 7241).Valentin Bartenev1-4/+4
The SPDY support is removed, as it's incompatible with the new module.
2015-09-03Upstream: fixed cache send error handling.Roman Arutyunyan1-11/+14
The value of NGX_ERROR, returned from filter handlers, was treated as a generic upstream error and changed to NGX_HTTP_INTERNAL_SERVER_ERROR before calling ngx_http_finalize_request(). This resulted in "header already sent" alert if header was already sent in filter handlers. The problem appeared in 54e9b83d00f0 (1.7.5).
2015-06-11Moved ngx_http_parse_time() to core, renamed accordingly.Maxim Dounin1-3/+3
The function is now called ngx_parse_http_time(), and can be used by any code to parse HTTP-style date and time. In particular, it will be used for OCSP stapling. For compatibility, a macro to map ngx_http_parse_time() to the new name provided for a while.
2015-05-16Upstream: $upstream_connect_time.Ruslan Ermilov1-1/+13
The variable keeps time spent on establishing a connection with the upstream server.
2015-05-16Upstream: times to obtain header/response are stored as ngx_msec_t.Ruslan Ermilov1-26/+11
2015-04-22Removed the obsolete aio module.Ruslan Ermilov1-1/+1
2015-04-07Upstream: abbreviated SSL handshake may interact badly with Nagle.Ruslan Ermilov1-1/+25