1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2025-02-24 09:48:14 +00:00

Merge pull request #1679 from pini-gh/pini-1609

Add test and fix `server 127.0.0.1 down` fallback for load balancing use case
This commit is contained in:
Nicolas Duchon 2021-07-03 23:48:09 +02:00 committed by GitHub
commit 323837bf70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 4 deletions

View File

@ -159,6 +159,7 @@ server {
# {{ $host }} # {{ $host }}
upstream {{ $upstream_name }} { upstream {{ $upstream_name }} {
{{ $server_found := "false" }}
{{ range $container := $containers }} {{ range $container := $containers }}
{{ $debug := (eq (coalesce $container.Env.DEBUG $debug_all "false") "true") }} {{ $debug := (eq (coalesce $container.Env.DEBUG $debug_all "false") "true") }}
{{/* If only 1 port exposed, use that as a default, else 80 */}} {{/* If only 1 port exposed, use that as a default, else 80 */}}
@ -173,7 +174,6 @@ upstream {{ $upstream_name }} {
# /!\ Virtual port not exposed # /!\ Virtual port not exposed
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ $server_found := "false" }}
{{ range $knownNetwork := $CurrentContainer.Networks }} {{ range $knownNetwork := $CurrentContainer.Networks }}
{{ range $containerNetwork := $container.Networks }} {{ range $containerNetwork := $container.Networks }}
{{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }} {{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }}
@ -204,11 +204,11 @@ upstream {{ $upstream_name }} {
{{ end }} {{ end }}
{{ end }} {{ end }}
{{ end }} {{ end }}
{{/* nginx-proxy/nginx-proxy#1105 */}} {{ end }}
{{ if (eq $server_found "false") }} {{/* nginx-proxy/nginx-proxy#1105 */}}
{{ if (eq $server_found "false") }}
# Fallback entry # Fallback entry
server 127.0.0.1 down; server 127.0.0.1 down;
{{ end }}
{{ end }} {{ end }}
} }

View File

@ -0,0 +1,8 @@
import pytest
def test_web_has_no_server_down(docker_compose, nginxproxy):
conf = nginxproxy.get_conf().decode('ASCII')
r = nginxproxy.get("http://web.nginx-proxy.tld/port")
assert r.status_code == 200
assert (r.text == "answer from port 81\n") or (r.text == "answer from port 82\n")
assert conf.count("server 127.0.0.1 down;") == 0

View File

@ -0,0 +1,30 @@
web1:
image: web
expose:
- "81"
environment:
WEB_PORTS: 81
VIRTUAL_HOST: web.nginx-proxy.tld
web2:
image: web
expose:
- "82"
environment:
WEB_PORTS: 83
VIRTUAL_HOST: web.nginx-proxy.tld
web3:
image: web
expose:
- "83"
environment:
WEB_PORTS: 83
VIRTUAL_HOST: web.nginx-proxy.tld
net: "none"
sut:
image: nginxproxy/nginx-proxy:test
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro