Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
caddyhttp: Auto-redirects from all bind addresses (fix #3443)
Matthew Holt committed
Jun 3, 2020 at 10:56 UTC
2d1f7b9da8ec23be10639e557536e029dedf83f6
1 file changed
+11
-7
modules/caddyhttp/autohttps.go
+11
-7
@@ -81,8 +81,10 @@ func (app *App) automaticHTTPSPhase1(ctx caddy.Context, repl *caddy.Replacer) er
81
uniqueDomainsForCerts := make(map[string]struct{})
82
83
// this maps domain names for automatic HTTP->HTTPS
84
- // redirects to their destination server address
85
- redirDomains := make(map[string]caddy.NetworkAddress)
84
+ // redirects to their destination server addresses
85
+ // (there might be more than 1 if bind is used; see
86
+ // https://github.com/caddyserver/caddy/issues/3443)
87
+ redirDomains := make(map[string][]caddy.NetworkAddress)
88
89
for srvName, srv := range app.Servers {
90
// as a prerequisite, provision route matchers; this is
@@ -220,7 +222,7 @@ func (app *App) automaticHTTPSPhase1(ctx caddy.Context, repl *caddy.Replacer) er
222
// an empty string to indicate a catch-all, which we have to
223
// treat special later
224
if len(serverDomainSet) == 0 {
223
- redirDomains[""] = addr
225
+ redirDomains[""] = append(redirDomains[""], addr)
226
continue
227
}
228
@@ -230,7 +232,7 @@ func (app *App) automaticHTTPSPhase1(ctx caddy.Context, repl *caddy.Replacer) er
232
// port, we'll have to choose one, so prefer the HTTPS port
233
if _, ok := redirDomains[d]; !ok ||
234
addr.StartPort == uint(app.httpsPort()) {
233
- redirDomains[d] = addr
235
+ redirDomains[d] = append(redirDomains[d], addr)
236
}
237
}
238
}
@@ -278,9 +280,11 @@ uniqueDomainsLoop:
280
// we need to reduce the mapping, i.e. group domains by address
281
// since new routes are appended to servers by their address
282
domainsByAddr := make(map[string][]string)
281
- for domain, addr := range redirDomains {
282
- addrStr := addr.String()
283
- domainsByAddr[addrStr] = append(domainsByAddr[addrStr], domain)
283
+ for domain, addrs := range redirDomains {
284
+ for _, addr := range addrs {
285
+ addrStr := addr.String()
286
+ domainsByAddr[addrStr] = append(domainsByAddr[addrStr], domain)
287
+ }
288
}
289
290
// these keep track of the redirect server address(es)