Skip to content

Commit 0faebb0

Browse files
authored
Merge pull request #12 from Muxi-X/feat/https
fix: autocert error
2 parents ad6bc82 + acd429b commit 0faebb0

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

cmd/cixing-gateway/main.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,27 @@ func main() {
6565
Email: contactEmail,
6666
}
6767

68+
// Use the manager's TLS config so the ACME ALPN protocol (acme-tls/1)
69+
// is enabled when Let's Encrypt chooses tls-alpn-01 challenges.
70+
tlsCfg := m.TLSConfig()
71+
tlsCfg.MinVersion = tls.VersionTLS12
72+
6873
httpsSrv := &http.Server{
6974
Addr: defaultHTTPSAddr,
7075
Handler: proxy,
7176
ReadHeaderTimeout: 10 * time.Second,
72-
TLSConfig: &tls.Config{
73-
GetCertificate: m.GetCertificate,
74-
MinVersion: tls.VersionTLS12,
75-
},
77+
TLSConfig: tlsCfg,
7678
}
7779

7880
// HTTP server for ACME HTTP-01 challenge and HTTPS redirect.
81+
redirectToHTTPS := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
82+
target := "https://" + domain + r.URL.RequestURI()
83+
http.Redirect(w, r, target, http.StatusPermanentRedirect)
84+
})
7985
httpSrv := &http.Server{
8086
Addr: defaultHTTPAddr,
8187
ReadHeaderTimeout: 10 * time.Second,
82-
Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
83-
if strings.HasPrefix(r.URL.Path, "/.well-known/acme-challenge/") {
84-
m.HTTPHandler(nil).ServeHTTP(w, r)
85-
return
86-
}
87-
target := "https://" + domain + r.URL.RequestURI()
88-
http.Redirect(w, r, target, http.StatusPermanentRedirect)
89-
}),
88+
Handler: m.HTTPHandler(redirectToHTTPS),
9089
}
9190

9291
errCh := make(chan error, 2)

0 commit comments

Comments
 (0)