mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-07-01 14:25:46 +00:00
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.
This commit is contained in:
committed by
Nicolas Duchon
parent
4b85e95824
commit
33eab70d32
1
test/test_virtual-path/alternate.conf
Normal file
1
test/test_virtual-path/alternate.conf
Normal file
@ -0,0 +1 @@
|
||||
rewrite ^/(web3|alt)/(.*) /$2 break;
|
1
test/test_virtual-path/bar.conf
Normal file
1
test/test_virtual-path/bar.conf
Normal file
@ -0,0 +1 @@
|
||||
add_header X-test bar;
|
1
test/test_virtual-path/foo.conf
Normal file
1
test/test_virtual-path/foo.conf
Normal file
@ -0,0 +1 @@
|
||||
add_header X-test f00;
|
@ -4,3 +4,35 @@ def test_default_root_response(docker_compose, nginxproxy):
|
||||
r = nginxproxy.get("http://nginx-proxy.test/")
|
||||
assert r.status_code == 418
|
||||
|
||||
@pytest.mark.parametrize("stub,header", [
|
||||
("nginx-proxy.test/web1", "bar"),
|
||||
("foo.nginx-proxy.test", "f00"),
|
||||
])
|
||||
def test_custom_applies(docker_compose, nginxproxy, stub, header):
|
||||
r = nginxproxy.get(f"http://{stub}/port")
|
||||
assert r.status_code == 200
|
||||
assert "X-test" in r.headers
|
||||
assert header == r.headers["X-test"]
|
||||
|
||||
@pytest.mark.parametrize("stub,code", [
|
||||
("nginx-proxy.test/foo", 418),
|
||||
("nginx-proxy.test/web2", 200),
|
||||
("nginx-proxy.test/web3", 200),
|
||||
("bar.nginx-proxy.test", 503),
|
||||
])
|
||||
def test_custom_does_not_apply(docker_compose, nginxproxy, stub, code):
|
||||
r = nginxproxy.get(f"http://{stub}/port")
|
||||
assert r.status_code == code
|
||||
assert "X-test" not in r.headers
|
||||
|
||||
@pytest.mark.parametrize("stub,port", [
|
||||
("nginx-proxy.test/web1", 81),
|
||||
("nginx-proxy.test/web2", 82),
|
||||
("nginx-proxy.test/web3", 83),
|
||||
("nginx-proxy.test/alt", 83),
|
||||
])
|
||||
def test_alternate(docker_compose, nginxproxy, stub, port):
|
||||
r = nginxproxy.get(f"http://{stub}/port")
|
||||
assert r.status_code == 200
|
||||
assert r.text == f"answer from port {port}\n"
|
||||
|
||||
|
@ -1,3 +1,12 @@
|
||||
|
||||
foo:
|
||||
image: web
|
||||
expose:
|
||||
- "42"
|
||||
environment:
|
||||
WEB_PORTS: "42"
|
||||
VIRTUAL_HOST: "foo.nginx-proxy.test"
|
||||
|
||||
web1:
|
||||
image: web
|
||||
expose:
|
||||
@ -18,6 +27,15 @@ web2:
|
||||
VIRTUAL_PATH: "/web2/"
|
||||
VIRTUAL_DEST: "/"
|
||||
|
||||
web3:
|
||||
image: web
|
||||
expose:
|
||||
- "83"
|
||||
environment:
|
||||
WEB_PORTS: "83"
|
||||
VIRTUAL_HOST: "nginx-proxy.test"
|
||||
VIRTUAL_PATH: "~ ^/(web3|alt)/"
|
||||
|
||||
sut:
|
||||
image: nginxproxy/nginx-proxy:test
|
||||
environment:
|
||||
@ -25,3 +43,7 @@ sut:
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ../lib/ssl/dhparam.pem:/etc/nginx/dhparam/dhparam.pem:ro
|
||||
- ./foo.conf:/etc/nginx/vhost.d/foo.nginx-proxy.test:ro
|
||||
- ./bar.conf:/etc/nginx/vhost.d/nginx-proxy.test_918d687a929083edd0c7224ee2293e0e7c062ab4_location:ro
|
||||
- ./alternate.conf:/etc/nginx/vhost.d/nginx-proxy.test_7fb22b74bbdf907425dbbad18e4462565cada230_location:ro
|
||||
|
||||
|
Reference in New Issue
Block a user