This commit is contained in:
pini-gh 2025-01-25 11:48:14 +00:00 committed by GitHub
commit d4650e645f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 64 additions and 1 deletions

View file

@ -361,8 +361,13 @@ upstream {{ $vpath.upstream }} {
{{- $args = dict "container" $container "path" $path "port" $port }} {{- $args = dict "container" $container "path" $path "port" $port }}
{{- template "container_port" $args }} {{- template "container_port" $args }}
{{- if $ip }} {{- if $ip }}
{{- $backup := parseBool (coalesce $container.Env.BACKUP_SERVER "false") }}
{{- if not $backup }}
{{- $servers = add1 $servers }} {{- $servers = add1 $servers }}
server {{ $ip }}:{{ $args.port }}; server {{ $ip }}:{{ $args.port }};
{{- else }}
server {{ $ip }}:{{ $args.port }} backup;
{{- end }}
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- end }} {{- end }}

View file

@ -0,0 +1,14 @@
import pytest
def test_web1_is_backup(docker_compose, nginxproxy):
for i in range(1, 10):
r = nginxproxy.get("http://web1.nginx-proxy.tld/port")
assert r.status_code == 200
assert r.text == "answer from port 91\n"
def test_web2_is_production(docker_compose, nginxproxy):
for i in range(1, 10):
r = nginxproxy.get("http://web2.nginx-proxy.tld/port")
assert r.status_code == 200
assert r.text == "answer from port 82\n"

View file

@ -0,0 +1,44 @@
version: "2"
services:
web1:
image: web
expose:
- "81"
environment:
WEB_PORTS: 81
VIRTUAL_HOST: web1.nginx-proxy.tld
network_mode: "none"
web1_backup:
image: web
expose:
- "91"
environment:
WEB_PORTS: 91
VIRTUAL_HOST: web1.nginx-proxy.tld
BACKUP_SERVER: "true"
web2:
image: web
expose:
- "82"
environment:
WEB_PORTS: 82
VIRTUAL_HOST: web2.nginx-proxy.tld
web2_backup:
image: web
expose:
- "92"
environment:
WEB_PORTS: 92
VIRTUAL_HOST: web2.nginx-proxy.tld
BACKUP_SERVER: "true"
sut:
image: nginxproxy/nginx-proxy:test
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
environment:
HTTPS_METHOD: nohttps