From 205f71196a5c0d40845054f60cd28d645f2e6770 Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sat, 16 Mar 2019 19:12:46 +0900 Subject: [PATCH] [NGinx template] Group by Host name instead of host --- Production/nginx.tmpl | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Production/nginx.tmpl b/Production/nginx.tmpl index 01ba8f0..7b7d88a 100644 --- a/Production/nginx.tmpl +++ b/Production/nginx.tmpl @@ -183,13 +183,11 @@ server { } {{ end }} -{{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }} +{{ range $host_name, $containers := groupByMulti $ "Env.VIRTUAL_HOST_NAME" "," }} -{{ $host := trim $host }} -{{ $is_regexp := hasPrefix "~" $host }} -{{ $upstream_name := when $is_regexp (sha1 $host) $host }} +{{ $host_name := trim $host_name }} +{{ $upstream_name := $host_name }} -# {{ $host }} upstream {{ $upstream_name }} { {{ range $container := $containers }} @@ -218,15 +216,14 @@ upstream {{ $upstream_name }} { {{ end }} {{ end }} } - +{{ range $host, $containers := groupByMulti $containers "Env.VIRTUAL_HOST" "," }} +{{ $host := trim $host }} {{ $default_host := or ($.Env.DEFAULT_HOST) "" }} {{ $default_server := index (dict $host "" $default_host "default_server") $host }} {{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost, falling back to "http" */}} {{ $proto := trim (or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http") }} -{{ $host_name := trim (or (first (groupByKeys $containers "Env.VIRTUAL_HOST_NAME")) "") }} - {{/* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external" */}} {{ $network_tag := or (first (groupByKeys $containers "Env.NETWORK_ACCESS")) "external" }} @@ -430,3 +427,4 @@ server { {{ end }} {{ end }} +{{ end }} \ No newline at end of file