Don't do HTTPS redirects for requests associated with Let's Encrypt certificate renewals.
This commit is contained in:
parent
309dd05f4d
commit
b8276dd23f
|
@ -116,6 +116,14 @@ func GetHandler(config Config) http.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func redirectTLS(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "https://"+r.Host+r.RequestURI, http.StatusMovedPermanently)
|
||||
}
|
||||
func GetRedirectTLSHandler(config Config) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
// Don't redirect Let's Encrypt requests
|
||||
if strings.HasPrefix(r.URL.Path, "/.well-known/acme-challenge/") {
|
||||
path := filepath.Join(config.DocBase, r.URL.Path)
|
||||
http.ServeFile(w, r, path)
|
||||
// But redirect everything else
|
||||
} else {
|
||||
http.Redirect(w, r, "https://"+r.Host+r.RequestURI, http.StatusMovedPermanently)
|
||||
}
|
||||
} }
|
||||
|
|
2
main.go
2
main.go
|
@ -34,7 +34,7 @@ func main() {
|
|||
errs := make(chan error, 2)
|
||||
// Start the HTTP server, which redirect all incoming connections to HTTPS
|
||||
http.HandleFunc("/", LoggingWrapper(logfile, GetHandler(config)))
|
||||
http_server := &http.Server{Addr: ":"+strconv.Itoa(config.HttpPort), Handler: http.HandlerFunc(redirectTLS)}
|
||||
http_server := &http.Server{Addr: ":"+strconv.Itoa(config.HttpPort), Handler: http.HandlerFunc(GetRedirectTLSHandler(config))}
|
||||
go func() {
|
||||
errs <- http_server.ListenAndServe()
|
||||
}()
|
||||
|
|
Loading…
Reference in New Issue