diff --git a/internal/router/router.go b/internal/router/router.go index dbd39fc99..939624cb7 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -91,15 +91,19 @@ func (r *router) Start() { http.Redirect(rw, r, target, http.StatusTemporaryRedirect) }) - // Start the LetsEncrypt autocert manager HTTP server. go func() { - addr := fmt.Sprintf("%s:%d", + // Take our own copy of HTTP server + // with updated autocert manager endpoint + srv := (*r.srv) //nolint + srv.Handler = r.certManager.HTTPHandler(redirect) + srv.Addr = fmt.Sprintf("%s:%d", viper.GetString(keys.BindAddress), viper.GetInt(keys.LetsEncryptPort), ) - logrus.Infof("letsencrypt listening on %s", addr) - if err := http.ListenAndServe(addr, r.certManager.HTTPHandler(redirect)); err != nil && + // Start the LetsEncrypt autocert manager HTTP server. + logrus.Infof("letsencrypt listening on %s", srv.Addr) + if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { logrus.Fatalf("letsencrypt: listen: %s", err) }