1
0
Fork 0
mirror of https://github.com/nginx-proxy/nginx-proxy synced 2024-06-01 20:36:23 +02:00
Commit Graph

220 Commits

Author SHA1 Message Date
Richard Hansen dfd4f54c61 fix: Don't downgrade from https to http if certificate is missing
Before, if a site's certificate was not found, the site was served
over http rather than https.  Failing open like this is problematic
for sites where security is important.  Presumably the user set
`HTTPS_METHOD` to a non-`noredirect` value (or left it unset) for a
good reason; we should honor it even if it means serving error
messages.

WARNING: This change breaks compatibility.  Any vhost where all of the
following are true will fail after this change:

  * `HTTPS_METHOD` is either unset or set to a value other than
    `nohttps`.
  * The vhost does not have its own certificate (`default.crt` doesn't
    count).
  * Clients expect to be able to access the vhost by using plain http
    to nginx-proxy.

To get the previous behavior, set `HTTPS_METHOD` to `nohttps` for the
vhost.
2023-05-14 14:56:43 -04:00
Nicolas Duchon e2539b04f5
fix: always on session cache on HTTPS fallback listener 2023-05-08 23:14:09 +02:00
Richard Hansen 035bd2b5ac fix: Remove `default_server` listen option from fallback server
This fixes a bug introduced in commit
9b4bb07b34.
2023-04-13 01:16:54 -04:00
Richard Hansen 9b4bb07b34
fix: Don't create fallback http(s) server when http(s) disabled
Before, a fallback http server was created to handle requests for
unknown virtual hosts even when `HTTPS_METHOD=nohttp`.  (In this case,
all http vhosts would be unknown.)  Likewise, a catch-all fallback
https server was still created even if `HTTPS_METHOD=nohttps`.

Now the fallback servers are created only if needed.  This brings the
behavior in line with the documentation and user expectation.  It will
also make it easier to implement a planned feature: different servers
on different ports.
2023-02-04 18:59:38 -05:00
Richard Hansen 9297e94389
fix: Emit TLS error if there are no certs available
Before, if neither the vhost-specific cert nor `default.crt` existed,
nginx-proxy would not create the https vhost.  This resulted in nginx
either refusing the connection or serving the wrong vhost depending on
whether there was another https vhost with a certificate.

Now nginx-proxy always creates an https server for a vhost, even if
the vhost-specific certificate and the default certificate are both
missing.  When both certs are missing, nginx is given empty
certificate data to make it possible for it to start up without an
error.  The empty certificate data causes the user to see a TLS error,
which is much easier to troubleshoot than a connection refused error
or serving the wrong vhost.
2023-02-02 22:02:06 -05:00
Richard Hansen 16066cab61
fix: Don't create cert error https server if https is not enabled 2023-02-02 17:17:00 -05:00
Richard Hansen 18d0671312
chore: Factor out duplicate checks for `default.crt`
for improved readability.
2023-02-01 18:56:16 -05:00
Richard Hansen 7a2b1f8833
chore: Split `$is_https` variable into two separate checks
for improved readability.
2023-02-01 18:17:43 -05:00
Niek 7ca1da8358
feat: Add support for HTTP load balancing between the proxy and upstream server groups (#2173)
Add initial tests

Newlines

Remove unused variable

Co-authored-by: Richard Hansen <rhansen@rhansen.org>

Change comment value

Co-authored-by: Richard Hansen <rhansen@rhansen.org>

add missing services line

Co-authored-by: Richard Hansen <rhansen@rhansen.org>

Use deploy.replicas

Remove details about choosing a load balancing method

Feedback note

Co-authored-by: Nicolas Duchon <nicolas.duchon@gmail.com>
2023-03-21 07:49:27 +01:00
Richard Hansen 49bb37dfdb feat: Add support for HTTP keep-alive between the proxy and upstream 2023-03-14 04:20:17 -04:00
Richard Hansen 364beed773 fix: Don't error if `$globals.CurrentContainer` is `nil`
Also:
  * Note when there are no networks.
  * Fix "networks available" comment.
2023-03-10 15:23:44 -05:00
Nicolas Duchon afd6544702
Merge pull request #2179 from rhansen/swarm
fix: Partially revert "chore: Remove support for legacy swarm"
2023-02-28 07:40:16 +01:00
Jan Malte Gerth 37134c44d7 fix: Sort networks and ports before iterating
This avoids unnecessary nginx restarts caused by config file churn.
2023-02-21 00:22:47 -05:00
Richard Hansen 6207be5f8f fix: Partially revert "chore: Remove support for legacy swarm"
This partially reverts commit 2494e20784
by ignoring any network named "ingress" when searching for a
container's IP address.

That commit was technically a backwards-incompatible change: Some
users use nginx-proxy with Swarm mode even though it is not fully
supported.  In such cases nginx-proxy should ignore the `ingress`
network, otherwise nginx will not be able to reach the
server (container-to-container traffic apparently doesn't work over
the Swarm `ingress` network).

The parts of that commit that examine the `SwarmNode` structure are
not reverted here because docker-gen does not currently populate that
structure -- not even when both docker-gen and the service task
container are running on the same manager node.
2023-02-17 01:52:05 -05:00
Richard Hansen 11a46f728c chore: Factor out container IP:port lookup
This will make planned future changes easier.
2023-02-01 03:06:39 -05:00
Richard Hansen 2494e20784 chore: Remove support for legacy swarm
It doesn't work with the newer Docker Swarm mode so it doesn't have
much value anymore.
2023-02-01 03:04:37 -05:00
Richard Hansen 2115974e93 feat: Add ability to completely override location blocks
Co-authored-by: Trent Harvey <trent@harvdog.net>
2023-01-31 04:53:12 -05:00
Richard Hansen 6162427c45 fix: Generate at most one `server` directive per container 2023-01-28 18:01:19 -05:00
Richard Hansen bcec2d9075 chore: Refactor `upstream` template for readability
In particular, reduce the nesting depth to make it easier to
understand what the code is doing by:

  * converting an $O(nm)$ nested loop into two serial $O(n)+O(m)$
    loops, and
  * consolidating similar nested `if` cases.
2023-01-28 18:01:19 -05:00
Richard Hansen daeed502cb feat: Add a warning comment if the container port is published 2023-01-28 18:01:19 -05:00
Richard Hansen 5a8a6ceae2 chore: Improve debug comments in `upstream` template 2023-01-28 18:01:19 -05:00
Richard Hansen 2760ead490 chore: Remove warning comment when port is not exposed
Exposing ports is largely deprecated because it doesn't actually do
anything in Docker.
2023-01-28 18:01:19 -05:00
Richard Hansen e97bf606c8 chore: Move version comment to the top of the template
to ensure that the version is always the first output line.

Also, always output `# nginx-proxy`, even if the version isn't known.
This makes it easier to find the start of the generated config in the
output of `nginx -T`.
2023-01-28 18:01:19 -05:00
Vincent Herlemont 07cc80ac6b
feat: Support LOG_FORMAT env variable (#2151) 2023-01-27 12:28:40 -05:00
Richard Hansen 8346b68a28 fix: Ignore `VIRTUAL_HOST` set to the empty string
Fixes #2144
2023-01-23 20:48:16 -05:00
Richard Hansen f8ae0a4b00 feat: `DEFAULT_ROOT=none` disables the default `location /` block 2023-01-23 20:47:00 -05:00
Richard Hansen 8fbc8514ef feat: Unconditionally produce debug comments
Rationale for eliminating the check to see if the `DEBUG` environment
variable holds a true value:
  * The `DEBUG` environment variable might be set on a container (for
    purposes specific to that container, not `nginx-proxy`) to a value
    that cannot be parsed as a bool, which would break `nginx-proxy`.
  * It simplifies the template.
  * It eliminates a cold code path.
  * It avoids heisenbugs.
  * It makes debugging easier for users.

Also delete the debug info tests, as they are fragile and they provide
limited value.

Alternatively, we could avoid collision with the container's use of
the `DEBUG` environment variable by using a container label [1] such
as `com.google.nginx-proxy.nginx-proxy.debug`.  I think doing so has
dubious value, especially if we want to attempt backwards
compatibility with the `DEBUG` environment variable.

Fixes #2139

[1] https://docs.docker.com/engine/reference/commandline/run/#-set-metadata-on-container--l---label---label-file

Co-authored-by: Nicolas Duchon <nicolas.duchon@gmail.com>
2023-01-18 17:27:04 -05:00
Richard Hansen 2427b383b5 chore: Move global variables to a `$globals` dict
Planned future changes will introduce more embedded templates, and the ability
to pass the globals to the templates will be useful.
2023-01-17 00:42:20 -05:00
Richard Hansen 1b253cd908 chore: Wrap long comments 2023-01-17 00:42:20 -05:00
Richard Hansen 0da38122bd chore: Consistent indentation 2023-01-17 00:42:20 -05:00
Richard Hansen f20662eeaa chore: Use `{{-` instead of `{{` to clean up whitespace 2023-01-17 00:42:20 -05:00
Richard Hansen d6d8b2205f chore: Fix comment terminators 2023-01-17 00:42:20 -05:00
Richard Hansen 4651bf411d chore: Fix comment for `$proxy_connection` variable 2023-01-17 00:42:20 -05:00
Richard Hansen 744bd82c54 chore: Combine identical HTTP and HTTPS servers 2023-01-17 00:42:20 -05:00
Richard Hansen 491642b1e9 chore: Factor out duplicate virtual path code 2023-01-17 00:42:20 -05:00
Richard Hansen 14d0f3f222 chore: Rename `$container` to `$containers`
The value is actually a slice/array of containers so it should be
pluralized.
2023-01-17 00:42:20 -05:00
Richard Hansen 05423c681a fix: Use `parseBool` to parse boolean strings 2023-01-17 00:42:20 -05:00
Richard Hansen c117ae8fd8 chore: Use boolean for `$server_found` variable 2023-01-17 00:42:20 -05:00
浊酒 af877cf784 feat: Add proxy header `X-Forwarded-Host`
Co-authored-by: Richard Hansen <rhansen@rhansen.org>
2022-12-26 17:59:50 -05:00
Nicolas Duchon 6f4f9ec20c
Merge pull request #1927 from rhansen/untrusted-headers
feat: Option to not trust `X-Forwarded-*` headers from clients
2022-12-26 20:47:05 +01:00
Richard Hansen 8aa00fcea2 feat: Option to not trust `X-Forwarded-*` headers from clients
If header values from a malicious client are passed to the backend
server unchecked and unchanged, the client may be able to subvert
security checks done by the backend server.
2022-12-19 02:48:01 -05:00
SilverFire - Dmitry Naumenko 510d376f00 Make sure networks order is the same 2022-05-11 12:56:18 +00:00
Nitin Jain 998d56c473 chore: indent location, upstream in template 2022-04-14 13:32:58 +05:30
Richard Hansen 55d913255d Fix IPv6 HTTP listen port 2022-03-20 18:54:07 -04:00
Nicolas Duchon b6b7133a2e
fix: minor fixes on nginx template 2022-02-24 15:17:47 +01:00
Alexander Lieret 08c9586346
fix: Handle VIRTUAL_PROTO on virtual path basis 2022-02-24 15:08:18 +01:00
Alexander Lieret 28c74e8dae
fix: Move NETWORK_ACCESS to location block 2022-02-24 15:08:18 +01:00
Nicolas Duchon efb250da01
fix: use most specific custom location config first
Co-authored-by: Jonathan Underwood <junderwood@bitcoinbank.co.jp>
2022-02-24 15:08:17 +01:00
Alexander Lieret 33eab70d32
feat: Add custom location block to virtual paths
This features allows the custom location blocks to be added to the
virtual path based routing. The custom config can be specified for each
container individually.
2022-02-24 15:08:17 +01:00
Alexander Lieret 4b85e95824
feat: Replace path stripping with variable
This commit removes the automatic path stripping and replaces it with a
user configurable environment variable. This can be set individually for
each container.
2022-02-24 15:08:17 +01:00