]> git.kaiwu.me - nginx.git/log
nginx.git
9 years agoImplemented the "server_tokens build" option.
Ruslan Ermilov [Tue, 31 Jan 2017 09:09:40 +0000 (12:09 +0300)]
Implemented the "server_tokens build" option.

Based on a patch by Tom Thorogood.

9 years agoUpdated OpenSSL used for win32 builds.
Maxim Dounin [Fri, 27 Jan 2017 16:06:35 +0000 (19:06 +0300)]
Updated OpenSSL used for win32 builds.

9 years agoUpstream: removed unused bl_time and bl_state fields.
Maxim Dounin [Thu, 26 Jan 2017 13:16:48 +0000 (16:16 +0300)]
Upstream: removed unused bl_time and bl_state fields.

9 years agoUpstream: removed unused ngx_http_upstream_conf_t.timeout field.
Thibault Charbonnier [Wed, 25 Jan 2017 01:52:39 +0000 (17:52 -0800)]
Upstream: removed unused ngx_http_upstream_conf_t.timeout field.

9 years agoUpstream: removed compatibility shims from ngx_http_upstream_t.
Vladimir Homutov [Wed, 25 Jan 2017 12:39:22 +0000 (15:39 +0300)]
Upstream: removed compatibility shims from ngx_http_upstream_t.

The type is no longer modified in NGINX Plus.

9 years agoVersion bump.
Vladimir Homutov [Thu, 26 Jan 2017 08:44:55 +0000 (11:44 +0300)]
Version bump.

9 years agorelease-1.11.9 tag
Maxim Dounin [Tue, 24 Jan 2017 14:02:19 +0000 (17:02 +0300)]
release-1.11.9 tag

9 years agonginx-1.11.9-RELEASE release-1.11.9
Maxim Dounin [Tue, 24 Jan 2017 14:02:18 +0000 (17:02 +0300)]
nginx-1.11.9-RELEASE

9 years agoUpdated zlib and PCRE used for win32 builds.
Maxim Dounin [Tue, 24 Jan 2017 13:41:29 +0000 (16:41 +0300)]
Updated zlib and PCRE used for win32 builds.

9 years agoUpstream: fixed cache corruption and socket leaks with aio_write.
Maxim Dounin [Fri, 20 Jan 2017 18:14:19 +0000 (21:14 +0300)]
Upstream: fixed cache corruption and socket leaks with aio_write.

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.

9 years agoRemoved pthread mutex / conditional variables debug messages.
Maxim Dounin [Fri, 20 Jan 2017 18:14:18 +0000 (21:14 +0300)]
Removed pthread mutex / conditional variables debug messages.

These messages doesn't seem to be needed in practice and only make
debugging logs harder to read.

9 years agoFixed trailer construction with limit on FreeBSD and macOS.
Maxim Dounin [Fri, 20 Jan 2017 18:12:48 +0000 (21:12 +0300)]
Fixed trailer construction with limit on FreeBSD and macOS.

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.

9 years agoImproved connection draining with small number of connections.
Maxim Dounin [Fri, 20 Jan 2017 11:03:20 +0000 (14:03 +0300)]
Improved connection draining with small number of connections.

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.

9 years agoAdded cycle parameter to ngx_drain_connections().
Maxim Dounin [Fri, 20 Jan 2017 11:03:19 +0000 (14:03 +0300)]
Added cycle parameter to ngx_drain_connections().

No functional changes, mostly style.

9 years agoStream: client SSL certificates were not checked in some cases.
Vladimir Homutov [Thu, 19 Jan 2017 13:20:07 +0000 (16:20 +0300)]
Stream: client SSL certificates were not checked in some cases.

If ngx_stream_ssl_init_connection() succeeded immediately, the check was not
done.

The bug had appeared in 1.11.8 (41cb1b64561d).

9 years agoStream: fixed handling of non-ssl sessions.
Vladimir Homutov [Thu, 19 Jan 2017 13:17:05 +0000 (16:17 +0300)]
Stream: fixed handling of non-ssl sessions.

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).

9 years agoMail: make it possible to disable SASL EXTERNAL.
Sergey Kandaurov [Thu, 12 Jan 2017 16:22:03 +0000 (19:22 +0300)]
Mail: make it possible to disable SASL EXTERNAL.

9 years agoStream: avoid infinite loop in case of socket read error.
Vladimir Homutov [Wed, 11 Jan 2017 09:01:56 +0000 (12:01 +0300)]
Stream: avoid infinite loop in case of socket read error.

9 years agoYear 2017.
Ruslan Ermilov [Tue, 10 Jan 2017 14:13:06 +0000 (17:13 +0300)]
Year 2017.

9 years agoVersion bump.
Ruslan Ermilov [Tue, 10 Jan 2017 14:13:01 +0000 (17:13 +0300)]
Version bump.

9 years agorelease-1.11.8 tag
Maxim Dounin [Tue, 27 Dec 2016 14:23:08 +0000 (17:23 +0300)]
release-1.11.8 tag

9 years agonginx-1.11.8-RELEASE release-1.11.8
Maxim Dounin [Tue, 27 Dec 2016 14:23:07 +0000 (17:23 +0300)]
nginx-1.11.8-RELEASE

9 years agoStream: speed up TCP peer recovery.
Roman Arutyunyan [Mon, 26 Dec 2016 11:27:05 +0000 (14:27 +0300)]
Stream: speed up TCP peer recovery.

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.

9 years agoWin32: compatiblity with OpenSSL 1.1.0.
Maxim Dounin [Sat, 24 Dec 2016 15:01:14 +0000 (18:01 +0300)]
Win32: compatiblity with OpenSSL 1.1.0.

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.

9 years agoWin32: support 64-bit compilation with MSVC.
Maxim Dounin [Sat, 24 Dec 2016 15:01:14 +0000 (18:01 +0300)]
Win32: support 64-bit compilation with MSVC.

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.

9 years agoWin32: fixed some warnings reported by Borland C.
Maxim Dounin [Sat, 24 Dec 2016 15:01:14 +0000 (18:01 +0300)]
Win32: fixed some warnings reported by Borland C.

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().

9 years agoWin32: minimized redefinition of ssize_t.
Maxim Dounin [Sat, 24 Dec 2016 15:01:14 +0000 (18:01 +0300)]
Win32: minimized redefinition of ssize_t.

All variants of GCC have ssize_t available, there is no need to
redefine it.

9 years agoWin32: minimized redefinition of intptr_t/uintptr_t.
Maxim Dounin [Sat, 24 Dec 2016 15:01:14 +0000 (18:01 +0300)]
Win32: minimized redefinition of intptr_t/uintptr_t.

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.

9 years agoWin32: stdint.h used for MinGW GCC.
Maxim Dounin [Sat, 24 Dec 2016 15:01:14 +0000 (18:01 +0300)]
Win32: stdint.h used for MinGW GCC.

There is no need to restrict stdint.h only to MinGW-w64 GCC, it is
available with MinGW GCC as well.

9 years agoWin32: fixed building with newer versions of MinGW GCC.
Maxim Dounin [Sat, 24 Dec 2016 15:01:14 +0000 (18:01 +0300)]
Win32: fixed building with newer versions of MinGW GCC.

Macro to indicate that off_t was defined has been changed, so we now
additionally define the new one.

9 years agoWin32: added a variable to specify compiler.
Maxim Dounin [Sat, 24 Dec 2016 15:01:14 +0000 (18:01 +0300)]
Win32: added a variable to specify compiler.

This allows to set a different one from command line when needed.
For example, to configure nginx with gcc as a compiler one could
use "make -f misc/GNUmakefile win32 CC=gcc".

9 years agoSSL: support AES256 encryption of tickets.
Maxim Dounin [Fri, 23 Dec 2016 14:28:20 +0000 (17:28 +0300)]
SSL: support AES256 encryption of tickets.

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.

9 years agoFixed missing "Location" field with some relative redirects.
Ruslan Ermilov [Thu, 22 Dec 2016 08:58:52 +0000 (11:58 +0300)]
Fixed missing "Location" field with some relative redirects.

Relative redirects did not work with directory redirects and
auto redirects issued by nginx.

9 years agoCore: relative redirects (closes #1000).
Ruslan Ermilov [Wed, 21 Dec 2016 20:10:51 +0000 (23:10 +0300)]
Core: relative redirects (closes #1000).

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.

9 years agoLimited recursion when evaluating variables.
Ruslan Ermilov [Wed, 21 Dec 2016 19:01:24 +0000 (22:01 +0300)]
Limited recursion when evaluating variables.

Unlimited recursion might cause stack exhaustion in some misconfigurations.

9 years agoStream: client SSL certificates verification support.
Vladimir Homutov [Tue, 20 Dec 2016 09:05:14 +0000 (12:05 +0300)]
Stream: client SSL certificates verification support.

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.

9 years agoStream ssl_preread: relaxed SSL version check.
Roman Arutyunyan [Mon, 19 Dec 2016 11:02:39 +0000 (14:02 +0300)]
Stream ssl_preread: relaxed SSL version check.

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.

9 years agoConfigure: detect nginx version for nginx.pm at make time.
Ruslan Ermilov [Fri, 16 Dec 2016 16:54:37 +0000 (19:54 +0300)]
Configure: detect nginx version for nginx.pm at make time.

9 years agoResolver: fixed handling of partially resolved SRV.
Dmitry Volyntsev [Fri, 16 Dec 2016 15:21:55 +0000 (18:21 +0300)]
Resolver: fixed handling of partially resolved SRV.

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.

9 years agoResolver: fixed a race between parallel name and addr resolves.
Dmitry Volyntsev [Fri, 16 Dec 2016 15:21:55 +0000 (18:21 +0300)]
Resolver: fixed a race between parallel name and addr resolves.

Previously, ngx_resolve_name() and ngx_resolve_addr() may have
rescheduled the resend timer while it was already in progress.

9 years agoResolver: fixed possible premature stop of the resend timer.
Dmitry Volyntsev [Fri, 16 Dec 2016 15:21:42 +0000 (18:21 +0300)]
Resolver: fixed possible premature stop of the resend timer.

Previously, ngx_resolve_name_done() and ngx_resolve_addr_done()
may have stopped the resend timer prematurely while srv_resend_queue
was not empty.

9 years agoResolver: fixed possible use-after-free in worker on fast shutdown.
Ruslan Ermilov [Fri, 16 Dec 2016 11:53:28 +0000 (14:53 +0300)]
Resolver: fixed possible use-after-free in worker on fast shutdown.

The fix in a3dc657f4e95 was incomplete.

9 years agoResolver: fixed possible use-after-free in worker on fast shutdown.
Ruslan Ermilov [Thu, 15 Dec 2016 18:44:34 +0000 (21:44 +0300)]
Resolver: fixed possible use-after-free in worker on fast shutdown.

9 years agoSSL: backed out changeset e7cb5deb951d, reimplemented properly.
Maxim Dounin [Thu, 15 Dec 2016 16:00:23 +0000 (19:00 +0300)]
SSL: backed out changeset e7cb5deb951d, reimplemented properly.

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().

9 years agoSSL: fix call to BIO_get_mem_data().
Piotr Sikora [Tue, 13 Dec 2016 22:19:30 +0000 (14:19 -0800)]
SSL: fix call to BIO_get_mem_data().

Fixes build with BoringSSL.

Signed-off-by: Piotr Sikora <piotrsikora@google.com>
9 years agoAccess log: support for json escaping.
Valentin Bartenev [Thu, 15 Dec 2016 13:25:42 +0000 (16:25 +0300)]
Access log: support for json escaping.

9 years agoContrib: added 'commentstring' for vim-commentary support.
Armin Grodon [Mon, 12 Dec 2016 23:49:44 +0000 (00:49 +0100)]
Contrib: added 'commentstring' for vim-commentary support.

9 years agoThe size of cmcf->phase_engine.handlers explained.
Ruslan Ermilov [Tue, 13 Dec 2016 19:00:49 +0000 (22:00 +0300)]
The size of cmcf->phase_engine.handlers explained.

9 years agoVersion bump.
Ruslan Ermilov [Tue, 13 Dec 2016 19:00:42 +0000 (22:00 +0300)]
Version bump.

9 years agorelease-1.11.7 tag
Maxim Dounin [Tue, 13 Dec 2016 15:21:23 +0000 (18:21 +0300)]
release-1.11.7 tag

9 years agonginx-1.11.7-RELEASE release-1.11.7
Maxim Dounin [Tue, 13 Dec 2016 15:21:23 +0000 (18:21 +0300)]
nginx-1.11.7-RELEASE

9 years agoHTTP/2: prevented creating temp files for requests without body.
Valentin Bartenev [Sat, 10 Dec 2016 10:23:38 +0000 (13:23 +0300)]
HTTP/2: prevented creating temp files for requests without body.

The problem was introduced by 52bd8cc17f34.

9 years agoHTTP/2: fixed posted streams handling.
Valentin Bartenev [Mon, 28 Nov 2016 17:58:14 +0000 (20:58 +0300)]
HTTP/2: fixed posted streams handling.

A bug was introduced by 82efcedb310b that could lead to timing out of
responses or segmentation fault, when accept_mutex was enabled.

The output queue in HTTP/2 can contain frames from different streams.
When the queue is sent, all related write handlers need to be called.
In order to do so, the streams were added to the h2c->posted queue
after handling sent frames.  Then this queue was processed in
ngx_http_v2_write_handler().

If accept_mutex is enabled, the event's "ready" flag is set but its
handler is not called immediately.  Instead, the event is added to
the ngx_posted_events queue.  At the same time in this queue can be
events from upstream connections.  Such events can result in sending
output queue before ngx_http_v2_write_handler() is triggered.  And
at the time ngx_http_v2_write_handler() is called, the output queue
can be already empty with some streams added to h2c->posted.

But after 82efcedb310b, these streams weren't processed if all frames
have already been sent and the output queue was empty.  This might lead
to a situation when a number of streams were get stuck in h2c->posted
queue for a long time.  Eventually these streams might get closed by
the send timeout.

In the worst case this might also lead to a segmentation fault, if
already freed stream was left in the h2c->posted queue.  This could
happen if one of the streams was terminated but wasn't closed, due to
the HEADERS frame or a partially sent DATA frame left in the output
queue.  If this happened the ngx_http_v2_filter_cleanup() handler
removed the stream from the h2c->waiting or h2c->posted queue on
termination stage, before the frame has been sent, and the stream
was again added to the h2c->posted queue after the frame was sent.

In order to fix all these problems and simplify the code, write
events of fake stream connections are now added to ngx_posted_events
instead of using a custom h2c->posted queue.

9 years agoMap: the "volatile" parameter.
Ruslan Ermilov [Thu, 8 Dec 2016 14:51:49 +0000 (17:51 +0300)]
Map: the "volatile" parameter.

By default, "map" creates cacheable variables [1].  With this
parameter it creates a non-cacheable variable.

An original idea was to deduce the cacheability of the "map"
variable by checking the cacheability of variables specified
in source and resulting values, but it turned to be too hard.
For example, a cacheable variable can be overridden with the
"set" directive or with the SSI "set" command.  Also, keeping
"map" variables cacheable by default is good for performance
reasons.  This required adding a new parameter.

[1] Before db699978a33f (1.11.0), the cacheability of the
"map" variable could vary depending on the cacheability of
variables specified in resulting values (ticket #1090).
This is believed to be a bug rather than a feature.

9 years agoMap: simplified "map" block parser.
Ruslan Ermilov [Thu, 8 Dec 2016 14:29:01 +0000 (17:29 +0300)]
Map: simplified "map" block parser.

No functional changes.

9 years agoSlab: commented bitmap initialization for small allocations.
Ruslan Ermilov [Thu, 8 Dec 2016 14:22:07 +0000 (17:22 +0300)]
Slab: commented bitmap initialization for small allocations.

9 years agoSlab: free pages statistics.
Ruslan Ermilov [Wed, 7 Dec 2016 19:25:37 +0000 (22:25 +0300)]
Slab: free pages statistics.

9 years agoSlab: slots statistics.
Ruslan Ermilov [Wed, 7 Dec 2016 19:25:37 +0000 (22:25 +0300)]
Slab: slots statistics.

For each slot, the number of total and used entries, as well as
the number of allocation requests and failures, are tracked.

9 years agoSlab: simplified some math.
Ruslan Ermilov [Wed, 7 Dec 2016 19:25:37 +0000 (22:25 +0300)]
Slab: simplified some math.

No functional changes.

9 years agoSlab: simplified allocation from slots.
Ruslan Ermilov [Wed, 7 Dec 2016 19:25:37 +0000 (22:25 +0300)]
Slab: simplified allocation from slots.

Removed code that would cause an endless loop, and removed condition
check that is always false.  The first page in the slot list is
guaranteed to satisfy an allocation.

9 years agoSlab: fixed the number of pages calculation.
Ruslan Ermilov [Wed, 7 Dec 2016 19:25:37 +0000 (22:25 +0300)]
Slab: fixed the number of pages calculation.

When estimating the number of pages, do not count memory for slots.
In some cases this gives one extra usable memory page.

9 years agoSlab: added comment about list heads.
Ruslan Ermilov [Wed, 7 Dec 2016 19:25:37 +0000 (22:25 +0300)]
Slab: added comment about list heads.

9 years agoSlab: improved code readability.
Ruslan Ermilov [Wed, 7 Dec 2016 19:25:37 +0000 (22:25 +0300)]
Slab: improved code readability.

No functional changes.

9 years agoCore: fixed environment on exit.
Maxim Dounin [Wed, 7 Dec 2016 16:03:31 +0000 (19:03 +0300)]
Core: fixed environment on exit.

On exit environment allocated from a pool is no longer available, leading
to a segmentation fault if, for example, a library tries to use it from
an atexit() handler.

Fix is to allocate environment via ngx_alloc() instead, and explicitly
free it using a pool cleanup handler if it's no longer used (e.g., on
configuration reload).

9 years agoPerl: removed special environment handling for the perl module.
Maxim Dounin [Wed, 7 Dec 2016 16:03:26 +0000 (19:03 +0300)]
Perl: removed special environment handling for the perl module.

In Perl 5.8.6 the default was switched to use putenv() when used as
embedded library unless "PL_use_safe_putenv = 0" is explicitly used
in the code.  Therefore, for modern versions of Perl it is no longer
necessary to restore previous environment when calling perl_destruct().

9 years agoPerl: added PERL_SET_INTERP().
Maxim Dounin [Wed, 7 Dec 2016 16:03:19 +0000 (19:03 +0300)]
Perl: added PERL_SET_INTERP().

For Perl compiled with threads, without PERL_SET_INTERP() the PL_curinterp
remains set to the first interpreter created (that is, one created at
original start).  As a result after a reload Perl thinks that operations
are done withing a thread, and, most notably, denies to change environment.

For example, the following code properly works on original start,
but fails after a reload:

    perl 'sub {
        my $r = shift;

        $r->send_http_header("text/plain");

        $ENV{TZ} = "UTC";
        $r->print("tz: " . $ENV{TZ} . " (localtime " . (localtime()) . ")\n");
        $ENV{TZ} = "Europe/Moscow";
        $r->print("tz: " . $ENV{TZ} . " (localtime " . (localtime()) . ")\n");

        return OK;
    }';

To fix this, PERL_SET_INTERP() added anywhere where PERL_SET_CONTEXT()
was previously used.

Note that PERL_SET_INTERP() doesn't seem to be documented anywhere.
Yet it is used in some other software, and also seems to be the only
solution possible.

9 years agoFixed spelling of logical AND operator, no functional changes.
Sergey Kandaurov [Wed, 7 Dec 2016 10:54:30 +0000 (13:54 +0300)]
Fixed spelling of logical AND operator, no functional changes.

Found by PVS-Studio.

9 years agoMp4: fixed setting wrong mdat atom size in very rare cases.
hucongcong [Tue, 22 Nov 2016 05:40:08 +0000 (13:40 +0800)]
Mp4: fixed setting wrong mdat atom size in very rare cases.

Atom size is the sum of atom header size and atom data size. The
specification says that the first 4 bytes are set to one when
the atom size is greater than the maximum unsigned 32-bit value.
Which means atom header size should be considered when the
comparison takes place between atom data size and 0xffffffff.

9 years agoSSL: $ssl_curves (ticket #1088).
Maxim Dounin [Mon, 5 Dec 2016 19:23:23 +0000 (22:23 +0300)]
SSL: $ssl_curves (ticket #1088).

The variable contains a list of curves as supported by the client.
Known curves are listed by their names, unknown ones are shown
in hex, e.g., "0x001d:prime256v1:secp521r1:secp384r1".

Note that OpenSSL uses session data for SSL_get1_curves(), and
it doesn't store full list of curves supported by the client when
serializing a session.  As a result $ssl_curves is only available
for new sessions (and will be empty for reused ones).

The variable is only meaningful when using OpenSSL 1.0.2 and above.
With older versions the variable is empty.

9 years agoSSL: $ssl_ciphers (ticket #870).
Maxim Dounin [Mon, 5 Dec 2016 19:23:23 +0000 (22:23 +0300)]
SSL: $ssl_ciphers (ticket #870).

The variable contains list of ciphers as supported by the client.
Known ciphers are listed by their names, unknown ones are shown
in hex, e.g., ""AES128-SHA:AES256-SHA:0x00ff".

The variable is fully supported only when using OpenSSL 1.0.2 and above.
With older version there is an attempt to provide some information
using SSL_get_shared_ciphers().  It only lists known ciphers though.
Moreover, as OpenSSL uses session data for SSL_get_shared_ciphers(),
and it doesn't store relevant data when serializing a session.  As
a result $ssl_ciphers is only available for new sessions (and not
available for reused ones) when using OpenSSL older than 1.0.2.

9 years agoSSL: $ssl_client_v_start, $ssl_client_v_end, $ssl_client_v_remain.
Maxim Dounin [Mon, 5 Dec 2016 19:23:23 +0000 (22:23 +0300)]
SSL: $ssl_client_v_start, $ssl_client_v_end, $ssl_client_v_remain.

9 years agoSSL: $ssl_client_verify extended with a failure reason.
Maxim Dounin [Mon, 5 Dec 2016 19:23:22 +0000 (22:23 +0300)]
SSL: $ssl_client_verify extended with a failure reason.

Now in case of a verification failure $ssl_client_verify contains
"FAILED:<reason>", similar to Apache's SSL_CLIENT_VERIFY, e.g.,
"FAILED:certificate has expired".

Detailed description of possible errors can be found in the verify(1)
manual page as provided by OpenSSL.

9 years agoOCSP stapling: improved error logging context.
Maxim Dounin [Mon, 5 Dec 2016 19:23:22 +0000 (22:23 +0300)]
OCSP stapling: improved error logging context.

It now logs the IP address of the responder used (if it's already known),
as well as the certificate name.

9 years agoOCSP stapling: added certificate name to warnings.
Maxim Dounin [Mon, 5 Dec 2016 19:23:22 +0000 (22:23 +0300)]
OCSP stapling: added certificate name to warnings.

9 years agoOCSP stapling: added http response status logging.
Maxim Dounin [Mon, 5 Dec 2016 19:23:22 +0000 (22:23 +0300)]
OCSP stapling: added http response status logging.

9 years agoOCSP stapling: style.
Maxim Dounin [Mon, 5 Dec 2016 19:23:22 +0000 (22:23 +0300)]
OCSP stapling: style.

9 years agoSlab: improved double free detection.
Ruslan Ermilov [Sat, 3 Dec 2016 07:01:39 +0000 (10:01 +0300)]
Slab: improved double free detection.

Previously, an attempt to double free the starting page of the
free range was not detected.

9 years agoSlab: always show the requested allocation size in debug messages.
Ruslan Ermilov [Sat, 3 Dec 2016 07:01:03 +0000 (10:01 +0300)]
Slab: always show the requested allocation size in debug messages.

Previously, allocations smaller than min_size were shown as min_size.

9 years agoSlab: style.
Ruslan Ermilov [Sat, 3 Dec 2016 06:55:40 +0000 (09:55 +0300)]
Slab: style.

Removed redundant parentheses.  No functional changes.

9 years agoEvents: improved error event handling for UDP sockets.
Dmitry Volyntsev [Mon, 21 Nov 2016 13:03:42 +0000 (16:03 +0300)]
Events: improved error event handling for UDP sockets.

Normally, the epoll module calls the read and write handlers depending
on whether EPOLLIN and EPOLLOUT are reported by epoll_wait().  No error
processing is done in the module, the handlers are expected to get an
error when doing I/O.

If an error event is reported without EPOLLIN and EPOLLOUT, the module
set both EPOLLIN and EPOLLOUT to ensure the error event is handled at
least in one active handler.

This works well unless the error is delivered along with only one of
EPOLLIN or EPOLLOUT, and the corresponding handler does not do any I/O.
For example, it happened when getting EPOLLERR|EPOLLOUT from
epoll_wait() upon receiving "ICMP port unreachable" while proxying UDP.
As the write handler had nothing to send it was not able to detect and
log an error, and did not switch to the next upstream.

The fix is to unconditionally set EPOLLIN and EPOLLOUT in case of an
error event.  In the aforementioned case, this causes the read handler
to be called which does recv() and detects an error.

In addition to the epoll module, analogous changes were made in
devpoll/eventport/poll.

9 years agoHTTP/2: fixed saving preread buffer to temp file (ticket #1143).
Valentin Bartenev [Mon, 28 Nov 2016 16:19:21 +0000 (19:19 +0300)]
HTTP/2: fixed saving preread buffer to temp file (ticket #1143).

Previously, a request body bigger than "client_body_buffer_size" wasn't written
into a temporary file if it has been pre-read entirely.  The preread buffer
is freed after processing, thus subsequent use of it might result in sending
corrupted body or cause a segfault.

9 years agoConfigure: honor dependencies of dynamic modules.
Maxim Dounin [Mon, 21 Nov 2016 13:49:19 +0000 (16:49 +0300)]
Configure: honor dependencies of dynamic modules.

Dependencies of dynamic modules are added to NGX_ADDON_DEPS (and
it is now used for dynamic modules) to be in line with what happens
in case of static compilation.

To avoid duplication, MAIL_DEPS and STREAM_DEPS are no longer passed
to auto/module when these modules are compiled as dynamic ones.  Mail
and stream dependencies are handled explicitly via corresponding
variables.

9 years agoVersion bump.
Maxim Dounin [Mon, 21 Nov 2016 13:49:17 +0000 (16:49 +0300)]
Version bump.

9 years agorelease-1.11.6 tag
Maxim Dounin [Tue, 15 Nov 2016 15:11:46 +0000 (18:11 +0300)]
release-1.11.6 tag

9 years agonginx-1.11.6-RELEASE release-1.11.6
Maxim Dounin [Tue, 15 Nov 2016 15:11:46 +0000 (18:11 +0300)]
nginx-1.11.6-RELEASE

9 years agoFixed a typo, removed an empty line.
Maxim Dounin [Mon, 14 Nov 2016 18:55:44 +0000 (21:55 +0300)]
Fixed a typo, removed an empty line.

9 years agoUpstream: handling of upstream SSL handshake timeouts.
Maxim Dounin [Mon, 14 Nov 2016 14:21:06 +0000 (17:21 +0300)]
Upstream: handling of upstream SSL handshake timeouts.

Previously SSL handshake timeouts were not properly logged, and resulted
in 502 errors instead of 504 (ticket #1126).

9 years agoRange filter: only initialize ctx->ranges in main request.
hucongcong [Thu, 10 Nov 2016 02:44:52 +0000 (10:44 +0800)]
Range filter: only initialize ctx->ranges in main request.

It is not necessary to initialize ctx->ranges in all request, because
ctx->ranges in subrequest will be reassigned to ctx->ranges of main
request.

9 years agoCore: slight optimization in ngx_chain_update_chains().
hucongcong [Thu, 10 Nov 2016 02:17:53 +0000 (10:17 +0800)]
Core: slight optimization in ngx_chain_update_chains().

It is not necessary to traverse *busy and link the *out when *out is NULL.

9 years agoStyle: switch.
Ruslan Ermilov [Fri, 4 Nov 2016 16:12:19 +0000 (19:12 +0300)]
Style: switch.

9 years agoCache: prefix-based temporary files.
Maxim Dounin [Thu, 3 Nov 2016 14:10:29 +0000 (17:10 +0300)]
Cache: prefix-based temporary files.

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).

9 years agoUpstream: avoid holding a cache node with upgraded connections.
Maxim Dounin [Thu, 3 Nov 2016 14:09:32 +0000 (17:09 +0300)]
Upstream: avoid holding a cache node with upgraded connections.

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.

9 years agoCache: proxy_cache_max_range_offset and friends.
Dmitry Volyntsev [Wed, 2 Nov 2016 17:05:21 +0000 (20:05 +0300)]
Cache: proxy_cache_max_range_offset and friends.

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.

9 years agoHTTP/2: flow control debugging.
Sergey Kandaurov [Wed, 2 Nov 2016 08:47:12 +0000 (11:47 +0300)]
HTTP/2: flow control debugging.

9 years agoPerl: fixed optimization in SSI command handler.
Maxim Dounin [Tue, 1 Nov 2016 17:39:21 +0000 (20:39 +0300)]
Perl: fixed optimization in SSI command handler.

As the pointer to the first argument was tested instead of the argument
itself, array of arguments was always created, even if there were no
arguments.  Fix is to test args[0] instead of args.

Found by Coverity (CID 1356862).

9 years agoHTTP/2: slightly improved debugging.
Ruslan Ermilov [Mon, 31 Oct 2016 20:38:51 +0000 (23:38 +0300)]
HTTP/2: slightly improved debugging.

9 years agoUpstream: removed ngx_http_upstream_srv_conf_t.default_port.
Ruslan Ermilov [Mon, 17 Oct 2016 11:30:54 +0000 (14:30 +0300)]
Upstream: removed ngx_http_upstream_srv_conf_t.default_port.

This is an API change.

9 years agoUpstream: don't consider default_port when matching upstreams.
Ruslan Ermilov [Mon, 17 Oct 2016 11:27:45 +0000 (14:27 +0300)]
Upstream: don't consider default_port when matching upstreams.

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.

9 years agoUpstream: consistently initialize explicit upstreams.
Ruslan Ermilov [Mon, 17 Oct 2016 11:14:02 +0000 (14:14 +0300)]
Upstream: consistently initialize explicit upstreams.

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; }

9 years agoUpstream: do not unnecessarily create per-request upstreams.
Ruslan Ermilov [Mon, 31 Oct 2016 15:33:36 +0000 (18:33 +0300)]
Upstream: do not unnecessarily create per-request upstreams.

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.