summaryrefslogtreecommitdiffhomepage
path: root/src (unfollow)
AgeCommit message (Collapse)AuthorFilesLines
2017-02-13Gzip: free chain links on the hot path (ticket #1046).Maxim Dounin1-6/+16
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-10Cache: increased cache header Vary and ETag lengths to 128.Maxim Dounin1-3/+3
This allows to store larger ETag values for proxy_cache_revalidate, including ones generated as SHA256, and cache responses with longer Vary (ticket #826). In particular, this fixes caching of Amazon S3 responses with CORS enabled, which now use "Vary: Origin, Access-Control-Request-Headers, Access-Control-Request-Method". Cache version bumped accordingly.
2017-02-10Slice filter: fetch slices in cloned subrequests.Roman Arutyunyan1-1/+4
Previously, slice subrequest location was selected based on request URI. If request is then redirected to a new location, its context array is cleared, making the slice module loose current slice range information. This lead to broken output. Now subrequests with the NGX_HTTP_SUBREQUEST_CLONE flag are created for slices. Such subrequests stay in the same location as the parent request and keep the right slice context.
2017-02-10Upstream: proxy_cache_background_update and friends.Roman Arutyunyan10-4/+107
The directives enable cache updates in subrequests.
2016-12-22Cache: support for stale-while-revalidate and stale-if-error.Roman Arutyunyan3-21/+93
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-02-08Request body: commented out debug printing of old buffers.Maxim Dounin1-0/+2
This is not really needed in practice, and causes excessive debug output in some of our tests.
2017-02-08Request body: c->error on "100 Continue" errors (ticket #1194).Maxim Dounin1-0/+2
2017-02-06SSL: clear error queue after OPENSSL_init_ssl().Sergey Kandaurov1-1/+11
The function may leave error in the error queue while returning success, e.g., when taking a DSO reference to itself as of OpenSSL 1.1.0d: https://git.openssl.org/?p=openssl.git;a=commit;h=4af9f7f Notably, this fixes alert seen with statically linked OpenSSL on some platforms. While here, check OPENSSL_init_ssl() return value.
2017-02-02SSL: fixed ssl_buffer_size on SNI virtual hosts (ticket #1192).Maxim Dounin1-0/+2
Previously, buffer size was not changed from the one saved during initial ngx_ssl_create_connection(), even if the buffer itself was not yet created. Fix is to change c->ssl->buffer_size in the SNI callback. Note that it should be also possible to update buffer size even in non-SNI virtual hosts as long as the buffer is not yet allocated. This looks like an overcomplication though.
2017-01-31Variables: generic prefix variables.Dmitry Volyntsev9-162/+266
2017-01-31Implemented the "server_tokens build" option.Ruslan Ermilov5-19/+92
Based on a patch by Tom Thorogood.
2017-01-26Upstream: removed unused bl_time and bl_state fields.Maxim Dounin1-3/+0
2017-01-24Upstream: removed unused ngx_http_upstream_conf_t.timeout field.Thibault Charbonnier1-1/+0
2017-01-25Upstream: removed compatibility shims from ngx_http_upstream_t.Vladimir Homutov1-3/+0
The type is no longer modified in NGINX Plus.
2017-01-26Version bump.Vladimir Homutov1-2/+2
2017-01-20Upstream: fixed cache corruption and socket leaks with aio_write.Maxim Dounin2-0/+28
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.
2017-01-20Removed pthread mutex / conditional variables debug messages.Maxim Dounin2-20/+0
These messages doesn't seem to be needed in practice and only make debugging logs harder to read.
2017-01-20Fixed trailer construction with limit on FreeBSD and macOS.Maxim Dounin3-7/+18
The ngx_chain_coalesce_file() function may produce more bytes to send then requested in the limit passed, as it aligns the last file position to send to memory page boundary. As a result, (limit - send) may become negative. This resulted in big positive number when converted to size_t while calling ngx_output_chain_to_iovec(). Another part of the problem is in ngx_chain_coalesce_file(): it changes cl to the next chain link even if the current buffer is only partially sent due to limit. Therefore, if a file buffer was not expected to be fully sent due to limit, and was followed by a memory buffer, nginx called sendfile() with a part of the file buffer, and the memory buffer in trailer. If there were enough room in the socket buffer, this resulted in a part of the file buffer being skipped, and corresponding part of the memory buffer sent instead. The bug was introduced in 8e903522c17a (1.7.8). Configurations affected are ones using limits, that is, limit_rate and/or sendfile_max_chunk, and memory buffers after file ones (may happen when using subrequests or with proxying with disk buffering). Fix is to explicitly check if (send < limit) before constructing trailer with ngx_output_chain_to_iovec(). Additionally, ngx_chain_coalesce_file() was modified to preserve unfinished file buffers in cl.
2017-01-20Improved connection draining with small number of connections.Maxim Dounin2-2/+7
Closing up to 32 connections might be too aggressive if worker_connections is set to a comparable number (and/or there are only a small number of reusable connections). If an occasional connection shorage happens in such a configuration, it leads to closing all reusable connections instead of gradually reducing keepalive timeout to a smaller value. To improve granularity in such configurations we now close no more than 1/8 of all reusable connections at once. Suggested by Joel Cunningham.
2017-01-20Added cycle parameter to ngx_drain_connections().Maxim Dounin1-5/+5
No functional changes, mostly style.
2017-01-19Stream: client SSL certificates were not checked in some cases.Vladimir Homutov1-1/+6
If ngx_stream_ssl_init_connection() succeeded immediately, the check was not done. The bug had appeared in 1.11.8 (41cb1b64561d).
2017-01-19Stream: fixed handling of non-ssl sessions.Vladimir Homutov1-1/+5
A missing check could cause ngx_stream_ssl_handler() to be applied to a non-ssl session, which resulted in a null pointer dereference if ssl_verify_client is enabled. The bug had appeared in 1.11.8 (41cb1b64561d).
2017-01-12Mail: make it possible to disable SASL EXTERNAL.Sergey Kandaurov3-4/+16
2017-01-11Stream: avoid infinite loop in case of socket read error.Vladimir Homutov1-2/+3
2017-01-10Version bump.Ruslan Ermilov1-2/+2
2016-12-26Stream: speed up TCP peer recovery.Roman Arutyunyan3-0/+37
Previously, an unavailable peer was considered recovered after a successful proxy session to this peer. Until then, only a single client connection per fail_timeout was allowed to be proxied to the peer. Since stream sessions can be long, it may take indefinite time for a peer to recover, limiting the ability of the peer to receive new connections. Now, a peer is considered recovered after a successful TCP connection is established to it. Balancers are notified of this event via the notify() callback.
2016-12-24Win32: compatiblity with OpenSSL 1.1.0.Maxim Dounin1-0/+3
OpenSSL 1.1.0 now uses normal "nmake; nmake install" instead of using custom "ms\do_ms.bat" script and "ms\nt.mak" makefile. And Configure now requires --prefix to be absolute, and no longer derives --openssldir from prefix (so it's specified explicitly). Generated libraries are now called "libcrypto.lib" and "libssl.lib" instead of "libeay32.lib" and "ssleay32.lib". Appropriate tests added to support both old and new variants. Additionally, openssl/lhash.h now triggers warning C4090 ('function' : different 'const' qualifiers), so the warning was disabled.
2016-12-24Win32: support 64-bit compilation with MSVC.Maxim Dounin4-16/+26
There are lots of C4244 warnings (conversion from 'type1' to 'type2', possible loss of data), so they were disabled. The same applies to C4267 warnings (conversion from 'size_t' to 'type', possible loss of data), most notably - conversion from ngx_str_t.len to ngx_variable_value_t.len (which is unsigned:28). Additionally, there is at least one case when it is not possible to fix the warning properly without introducing win32-specific code: recv() on win32 uses "int len", while POSIX defines "size_t len". The ssize_t type now properly defined for 64-bit compilation with MSVC. Caught by warning C4305 (truncation from '__int64' to 'ssize_t'), on "cutoff = NGX_MAX_SIZE_T_VALUE / 10" in ngx_atosz()). Several C4334 warnings (result of 32-bit shift implicitly converted to 64 bits) were fixed by adding explicit conversions. Several C4214 warnings (nonstandard extension used: bit field types other than int) in ngx_http_script.h fixed by changing bit field types from uintptr_t to unsigned.
2016-12-24Win32: fixed some warnings reported by Borland C.Maxim Dounin5-11/+14
Most notably, warning W8012 (comparing signed and unsigned values) reported in multiple places where an unsigned value of small type (e.g., u_short) is promoted to an int and compared to an unsigned value. Warning W8072 (suspicious pointer arithmetic) disabled, it is reported when we increment base pointer in ngx_shm_alloc().
2016-12-24Win32: minimized redefinition of ssize_t.Maxim Dounin1-1/+1
All variants of GCC have ssize_t available, there is no need to redefine it.
2016-12-24Win32: minimized redefinition of intptr_t/uintptr_t.Maxim Dounin1-1/+1
These types are available with MSVC (at least since 2003, in stddef.h), all variants of GCC (in stdint.h) and Watcom C. We need to define them only for Borland C.
2016-12-24Win32: stdint.h used for MinGW GCC.Maxim Dounin1-1/+1
There is no need to restrict stdint.h only to MinGW-w64 GCC, it is available with MinGW GCC as well.
2016-12-24Win32: fixed building with newer versions of MinGW GCC.Maxim Dounin1-0/+1
Macro to indicate that off_t was defined has been changed, so we now additionally define the new one.
2016-12-23SSL: support AES256 encryption of tickets.Maxim Dounin2-16/+47
This implies ticket key size of 80 bytes instead of previously used 48, as both HMAC and AES keys are 32 bytes now. When an old 48-byte ticket key is provided, we fall back to using backward-compatible AES128 encryption. OpenSSL switched to using AES256 in 1.1.0, and we are providing equivalent security. While here, order of HMAC and AES keys was reverted to make the implementation compatible with keys used by OpenSSL with SSL_CTX_set_tlsext_ticket_keys(). Prodded by Christian Klinger.
2016-12-22Fixed missing "Location" field with some relative redirects.Ruslan Ermilov4-18/+10
Relative redirects did not work with directory redirects and auto redirects issued by nginx.
2016-12-21Core: relative redirects (closes #1000).Ruslan Ermilov4-2/+16
The current version of HTTP/1.1 standard allows relative references in redirects (https://tools.ietf.org/html/rfc7231#section-7.1.2). Allow this form for redirects generated by nginx by introducing the new directive absolute_redirect.
2016-12-21Limited recursion when evaluating variables.Ruslan Ermilov2-13/+61
Unlimited recursion might cause stack exhaustion in some misconfigurations.
2016-12-20Stream: client SSL certificates verification support.Vladimir Homutov2-0/+157
New directives: "ssl_verify_client", "ssl_verify_depth", "ssl_client_certificate", "ssl_trusted_certificate", and "ssl_crl". New variables: $ssl_client_cert, $ssl_client_raw_cert, $ssl_client_s_dn, $ssl_client_i_dn, $ssl_client_serial, $ssl_client_fingerprint, $ssl_client_verify, $ssl_client_v_start, $ssl_client_v_end, and $ssl_client_v_remain.
2016-12-19Stream ssl_preread: relaxed SSL version check.Roman Arutyunyan1-1/+1
SSL version 3.0 can be specified by the client at the record level for compatibility reasons. Previously, ssl_preread module rejected such connections, presuming they don't have SNI. Now SSL 3.0 is allowed at the record level.
2016-12-16Resolver: fixed handling of partially resolved SRV.Dmitry Volyntsev1-1/+5
The resolver handles SRV requests in two stages. In the first stage it gets all SRV RRs, and in the second stage it resolves the names from SRV RRs into addresses. Previously, if a response to an SRV request was cached, the queries to resolve names were not limited by a timeout. If a response to any of these queries was not received, the SRV request could never complete. If a response to an SRV request was not cached, and some of the queries to resolve names timed out, NGX_RESOLVE_TIMEDOUT was returned instead of successfully resolved addresses. To fix both issues, resolving of names is now always limited by a timeout.
2016-12-16Resolver: fixed a race between parallel name and addr resolves.Dmitry Volyntsev1-2/+2
Previously, ngx_resolve_name() and ngx_resolve_addr() may have rescheduled the resend timer while it was already in progress.
2016-12-16Resolver: fixed possible premature stop of the resend timer.Dmitry Volyntsev1-0/+1
Previously, ngx_resolve_name_done() and ngx_resolve_addr_done() may have stopped the resend timer prematurely while srv_resend_queue was not empty.
2016-12-16Resolver: fixed possible use-after-free in worker on fast shutdown.Ruslan Ermilov1-0/+4
The fix in a3dc657f4e95 was incomplete.
2016-12-15Resolver: fixed possible use-after-free in worker on fast shutdown.Ruslan Ermilov1-0/+4
2016-12-15SSL: backed out changeset e7cb5deb951d, reimplemented properly.Maxim Dounin2-6/+6
Changeset e7cb5deb951d breaks build on CentOS 5 with "dereferencing type-punned pointer will break strict-aliasing rules" warning. It is backed out. Instead, to keep builds with BoringSSL happy, type of the "value" variable changed to "char *", and an explicit cast added before calling ngx_parse_http_time().
2016-12-13SSL: fix call to BIO_get_mem_data().Piotr Sikora2-2/+2
Fixes build with BoringSSL. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2016-12-15Access log: support for json escaping.Valentin Bartenev2-12/+154
2016-12-13The size of cmcf->phase_engine.handlers explained.Ruslan Ermilov1-1/+4
2016-12-13Version bump.Ruslan Ermilov1-2/+2