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
Enable skipping just certificate management for some auto HTTPS names
Matthew Holt committed
Jun 26, 2019 at 10:57 UTC
a524bcfe78e8067b8224b1794c6842d9c2c7e8cf
2 files changed
+21
-9
modules/caddyhttp/caddyhttp.go
+11
-5
@@ -210,7 +210,8 @@ func (app *App) automaticHTTPS() error {
210
for _, m := range matcherSet {
211
if hm, ok := m.(*MatchHost); ok {
212
for _, d := range *hm {
213
- if certmagic.HostQualifies(d) && !srv.AutoHTTPS.HostSkipped(d) {
213
+ if certmagic.HostQualifies(d) &&
214
+ !srv.AutoHTTPS.Skipped(d, srv.AutoHTTPS.Skip) {
215
domainSet[d] = struct{}{}
216
}
217
}
@@ -221,9 +222,12 @@ func (app *App) automaticHTTPS() error {
222
223
if len(domainSet) > 0 {
224
// marshal the domains into a slice
224
- var domains []string
225
+ var domains, domainsForCerts []string
226
for d := range domainSet {
227
domains = append(domains, d)
228
+ if !srv.AutoHTTPS.Skipped(d, srv.AutoHTTPS.SkipCerts) {
229
+ domainsForCerts = append(domainsForCerts, d)
230
+ }
231
}
232
233
// ensure that these certificates are managed properly;
@@ -245,13 +249,13 @@ func (app *App) automaticHTTPS() error {
249
acmeManager.SetDefaults()
250
tlsApp.Automation.Policies = append(tlsApp.Automation.Policies,
251
caddytls.AutomationPolicy{
248
- Hosts: domains,
252
+ Hosts: domainsForCerts,
253
Management: acmeManager,
254
})
255
256
// manage their certificates
253
- log.Printf("[INFO] Enabling automatic HTTPS for %v", domains)
254
- err := tlsApp.Manage(domains)
257
+ log.Printf("[INFO] Enabling automatic HTTPS certificates for %v", domainsForCerts)
258
+ err := tlsApp.Manage(domainsForCerts)
259
if err != nil {
260
return fmt.Errorf("%s: managing certificate for %s: %s", srvName, domains, err)
261
}
@@ -267,6 +271,8 @@ func (app *App) automaticHTTPS() error {
271
continue
272
}
273
274
+ log.Printf("[INFO] Enabling automatic HTTP->HTTPS redirects for %v", domains)
275
+
276
// create HTTP->HTTPS redirects
277
for _, addr := range srv.Listen {
278
netw, host, port, err := splitListenAddr(addr)
modules/caddyhttp/server.go
+10
-4
@@ -133,12 +133,18 @@ type AutoHTTPSConfig struct {
133
// in automatic HTTPS (they will not have certificates
134
// loaded nor redirects applied).
135
Skip []string `json:"skip,omitempty"`
136
+
137
+ // Hosts/domain names listed here will still be enabled
138
+ // for automatic HTTPS (unless in the Skip list), except
139
+ // that certificates will not be provisioned and managed
140
+ // for these names.
141
+ SkipCerts []string `json:"skip_certificates,omitempty"`
142
}
143
138
-// HostSkipped returns true if name is supposed to be skipped
139
-// when setting up automatic HTTPS.
140
-func (ahc AutoHTTPSConfig) HostSkipped(name string) bool {
141
- for _, n := range ahc.Skip {
144
+// Skipped returns true if name is in skipSlice, which
145
+// should be one of the Skip* fields on ahc.
146
+func (ahc AutoHTTPSConfig) Skipped(name string, skipSlice []string) bool {
147
+ for _, n := range skipSlice {
148
if name == n {
149
return true
150
}