diff --git a/nginx.tmpl b/nginx.tmpl index 20688da..4a5e76b 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -85,8 +85,9 @@ server { {{ end }} {{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }} - -upstream {{ $host }} { +{{ $upstream_name := sha1 $host }} +# {{ $host }} +upstream {{ $upstream_name }} { {{ range $container := $containers }} {{ $addrLen := len $container.Addresses }} @@ -179,9 +180,9 @@ server { location / { {{ if eq $proto "uwsgi" }} include uwsgi_params; - uwsgi_pass {{ trim $proto }}://{{ trim $host }}; + uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }}; {{ else }} - proxy_pass {{ trim $proto }}://{{ trim $host }}; + proxy_pass {{ trim $proto }}://{{ trim $upstream_name }}; {{ end }} {{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }} auth_basic "Restricted {{ $host }}"; @@ -213,9 +214,9 @@ server { location / { {{ if eq $proto "uwsgi" }} include uwsgi_params; - uwsgi_pass {{ trim $proto }}://{{ trim $host }}; + uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }}; {{ else }} - proxy_pass {{ trim $proto }}://{{ trim $host }}; + proxy_pass {{ trim $proto }}://{{ trim $upstream_name }}; {{ end }} {{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }} auth_basic "Restricted {{ $host }}"; diff --git a/test/wildcard-hosts.bats b/test/wildcard-hosts.bats index 8491e4b..826009e 100644 --- a/test/wildcard-hosts.bats +++ b/test/wildcard-hosts.bats @@ -43,13 +43,28 @@ function setup { @test "[$TEST_FILE] VIRTUAL_HOST=~^foo\.bar\..*\.bats" { # WHEN - prepare_web_container bats-wildcard-hosts-2 80 -e VIRTUAL_HOST=~^foo\.bar\..*\.bats - dockergen_wait_for_event $SUT_CONTAINER start bats-wildcard-hosts-2 + prepare_web_container bats-wildcard-hosts-3 80 -e VIRTUAL_HOST=~^foo\.bar\..*\.bats + dockergen_wait_for_event $SUT_CONTAINER start bats-wildcard-hosts-3 sleep 1 # THEN assert_200 foo.bar.whatever.bats assert_200 foo.bar.why.not.bats + assert_200 foo.bar.why.not.bats-to-infinity-and-beyond + assert_503 unexpected.host.bats + +} + +@test "[$TEST_FILE] VIRTUAL_HOST=~^foo\.bar\..*\.bats$" { + # WHEN + prepare_web_container bats-wildcard-hosts-4 80 -e VIRTUAL_HOST=~^foo\.bar\..*\.bats$ + dockergen_wait_for_event $SUT_CONTAINER start bats-wildcard-hosts-4 + sleep 1 + + # THEN + assert_200 foo.bar.whatever.bats + assert_200 foo.bar.why.not.bats + assert_503 foo.bar.why.not.bats-to-infinity-and-beyond assert_503 unexpected.host.bats }