diff --git a/caddyhttp/proxy/upstream.go b/caddyhttp/proxy/upstream.go index 64f8c5513..228e5d84a 100644 --- a/caddyhttp/proxy/upstream.go +++ b/caddyhttp/proxy/upstream.go @@ -69,6 +69,19 @@ func NewStaticUpstreams(c caddyfile.Dispenser) ([]Upstream, error) { to = append(to, parsed...) } + if len(to) == 0 { + return upstreams, c.ArgErr() + } + + upstream.Hosts = make([]*UpstreamHost, len(to)) + for i, host := range to { + uh, err := upstream.NewHost(host) + if err != nil { + return upstreams, err + } + upstream.Hosts[i] = uh + } + for c.NextBlock() { switch c.Val() { case "upstream": @@ -87,19 +100,6 @@ func NewStaticUpstreams(c caddyfile.Dispenser) ([]Upstream, error) { } } - if len(to) == 0 { - return upstreams, c.ArgErr() - } - - upstream.Hosts = make([]*UpstreamHost, len(to)) - for i, host := range to { - uh, err := upstream.NewHost(host) - if err != nil { - return upstreams, err - } - upstream.Hosts[i] = uh - } - if upstream.HealthCheck.Path != "" { upstream.HealthCheck.Client = http.Client{ Timeout: upstream.HealthCheck.Timeout, @@ -287,7 +287,7 @@ func parseBlock(c *caddyfile.Dispenser, u *staticUpstream) error { } u.downstreamHeaders.Add(header, value) case "transparent": - u.upstreamHeaders.Add("Host", "{host}") + u.upstreamHeaders.Add("Host", u.Hosts[0].Name) u.upstreamHeaders.Add("X-Real-IP", "{remote}") u.upstreamHeaders.Add("X-Forwarded-For", "{remote}") u.upstreamHeaders.Add("X-Forwarded-Proto", "{scheme}")