Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 12, 22:00 UTC
httpcaddyfile: Enable TLS for catch-all site if `tls` directive is specified (#5808)
Đỗ Trọng Hải committed
Oct 11, 2023 at 04:46 UTC
df9950297793fbe3930cd3151b6f1a3cea893a38
2 files changed
+48
-1
caddyconfig/httpcaddyfile/httptype.go
+11
-1
@@ -716,10 +716,20 @@ func (st *ServerType) serversFromPairings(
716
}
717
}
718
719
+ // If TLS is specified as directive, it will also result in 1 or more connection policy being created
720
+ // Thus, catch-all address with non-standard port, e.g. :8443, can have TLS enabled without
721
+ // specifying prefix "https://"
722
+ // Second part of the condition is to allow creating TLS conn policy even though `auto_https` has been disabled
723
+ // ensuring compatibility with behavior described in below link
724
+ // https://caddy.community/t/making-sense-of-auto-https-and-why-disabling-it-still-serves-https-instead-of-http/9761
725
+ createdTLSConnPolicies, ok := sblock.pile["tls.connection_policy"]
726
+ hasTLSEnabled := (ok && len(createdTLSConnPolicies) > 0) ||
727
+ (addr.Host != "" && srv.AutoHTTPS != nil && !sliceContains(srv.AutoHTTPS.Skip, addr.Host))
728
+
729
// we'll need to remember if the address qualifies for auto-HTTPS, so we
730
// can add a TLS conn policy if necessary
731
if addr.Scheme == "https" ||
722
- (addr.Scheme != "http" && addr.Host != "" && addr.Port != httpPort) {
732
+ (addr.Scheme != "http" && addr.Port != httpPort && hasTLSEnabled) {
733
addressQualifiesForTLS = true
734
}
735
// predict whether auto-HTTPS will add the conn policy for us; if so, we
caddytest/integration/caddyfile_adapt/enable_tls_for_catch_all_site.txt
new
+37
@@ -0,0 +1,37 @@
1
+:8443 {
2
+ tls internal {
3
+ on_demand
4
+ }
5
+}
6
+----------
7
+{
8
+ "apps": {
9
+ "http": {
10
+ "servers": {
11
+ "srv0": {
12
+ "listen": [
13
+ ":8443"
14
+ ],
15
+ "tls_connection_policies": [
16
+ {}
17
+ ]
18
+ }
19
+ }
20
+ },
21
+ "tls": {
22
+ "automation": {
23
+ "policies": [
24
+ {
25
+ "issuers": [
26
+ {
27
+ "module": "internal"
28
+ }
29
+ ],
30
+ "on_demand": true
31
+ }
32
+ ]
33
+ }
34
+ }
35
+ }
36
+}
37
+