mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-07-01 14:25:46 +00:00
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>
This commit is contained in:
16
test/test_loadbalancing.py
Normal file
16
test/test_loadbalancing.py
Normal file
@ -0,0 +1,16 @@
|
||||
import pytest
|
||||
import re
|
||||
|
||||
def test_loadbalance_hash(docker_compose, nginxproxy):
|
||||
conf = nginxproxy.get_conf().decode('ASCII')
|
||||
r1 = nginxproxy.get("http://loadbalance-enabled.nginx-proxy.tld")
|
||||
r2 = nginxproxy.get("http://loadbalance-enabled.nginx-proxy.tld")
|
||||
assert re.search(r"hash \$remote_addr\;", conf)
|
||||
assert r1.status_code == 200
|
||||
assert r2.text == r1.text
|
||||
|
||||
def test_loadbalance_roundrobin(docker_compose, nginxproxy):
|
||||
r1 = nginxproxy.get("http://loadbalance-disabled.nginx-proxy.tld")
|
||||
r2 = nginxproxy.get("http://loadbalance-disabled.nginx-proxy.tld")
|
||||
assert r1.status_code == 200
|
||||
assert r2.text != r1.text
|
27
test/test_loadbalancing.yml
Normal file
27
test/test_loadbalancing.yml
Normal file
@ -0,0 +1,27 @@
|
||||
services:
|
||||
loadbalance-hash:
|
||||
image: web
|
||||
expose:
|
||||
- "81"
|
||||
environment:
|
||||
WEB_PORTS: 81
|
||||
VIRTUAL_HOST: loadbalance-enabled.nginx-proxy.tld
|
||||
labels:
|
||||
com.github.nginx-proxy.nginx-proxy.loadbalance: "hash $$remote_addr;"
|
||||
deploy:
|
||||
replicas: 2
|
||||
|
||||
loadbalance-roundrobin:
|
||||
image: web
|
||||
expose:
|
||||
- "82"
|
||||
environment:
|
||||
WEB_PORTS: 82
|
||||
VIRTUAL_HOST: loadbalance-disabled.nginx-proxy.tld
|
||||
deploy:
|
||||
replicas: 2
|
||||
|
||||
sut:
|
||||
image: nginxproxy/nginx-proxy:test
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
Reference in New Issue
Block a user