Repository: caddyserver/caddy (language: go)

Issue:
Auto HTTPS redirects to the wrong entry
### 1. Caddy version (caddy version):
2.4.6

### 2. How I run Caddy:

Via docker compose on Amazon ECS.

#### a. System environment:

Amazon ECS, Fargate. Docker compose file with docker client using ECS context.

#### b. Command:

Caddyfile is base64 encoded in an environment variable. Then is decoded and copied to `/etc/caddy/Caddyfile`. Then `caddy run --config /etc/caddy/Caddyfile --adapter caddyfile`.

#### c. Service/unit/compose file:

```yaml
services:
  caddy:
    image: caddy:2.4.6-alpine
    ports:
      - "80:80"
      - "443:443"
      - "2345:2345"
    volumes:
      - caddy_data:/data
      - caddy_config:/config
    command: ["sh", "-c", "echo ${CADDYFILE_B64} | base64 -d > /etc/caddy/Caddyfile && caddy run --config /etc/caddy/Caddyfile --adapter caddyfile"]
volumes:
  caddy_data:
  caddy_config:
```

#### d. My complete Caddyfile or JSON config:

```
{
    debug
}

https://example.example.com {
    reverse_proxy http://localhost:1234
}

https://example.example.com:2345 {
    reverse_proxy http://localhost:2345
}
```

### 3. The problem I’m having:

When we do go to http://example.example.com/, we get redirected to https://example.example.com:2345/ instead of https://example.example.com/.

```
% curl -IL http://example.example.com                                                                                          
HTTP/1.1 308 Permanent Redirect
Connection: close
Location: https://example.example.com:2345/
Server: Caddy
Date: Wed, 12 Jan 2022 14:57:00 GMT

HTTP/2 200 
content-type: application/octet-stream
date: Wed, 12 Jan 2022 14:57:00 GMT
server: Caddy
content-length: 0
```

### 4. What I already tried:

Tried changing the order of the entries.

Created this issue as suggested in the [forum post ](https://caddy.community/t/entry-with-no-port-specified-redirects-to-wrong-port-entry/14708)


Discussion / hints:
Thanks. I guess if the target port is ambiguous, we should prefer the HTTPS port if that's one of the options.

Fix patch:
diff --git a/modules/caddyhttp/autohttps.go b/modules/caddyhttp/autohttps.go
index da4428dbdb8..6c37d7026fe 100644
--- a/modules/caddyhttp/autohttps.go
+++ b/modules/caddyhttp/autohttps.go
@@ -232,7 +232,7 @@ func (app *App) automaticHTTPSPhase1(ctx caddy.Context, repl *caddy.Replacer) er
 				// port, we'll have to choose one, so prefer the HTTPS port
 				if _, ok := redirDomains[d]; !ok ||
 					addr.StartPort == uint(app.httpsPort()) {
-					redirDomains[d] = append(redirDomains[d], addr)
+					redirDomains[d] = []caddy.NetworkAddress{addr}
 				}
 			}
 		}


Test patch: