@@ -155,7 +155,8 @@ func (ln tcpKeepAliveListener) Accept() (c net.Conn, err error) {
155155
156156func redirectToHTTPS(opts *Options, h http.Handler) http.Handler {
157157 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
158− if opts.ForceHTTPS && r.TLS == nil {
158+ proto := r.Header.Get("X-Forwarded-Proto")
159+ if opts.ForceHTTPS && r.TLS == nil && strings.ToLower(proto) != "https" {
159160 http.Redirect(w, r, opts.HTTPSAddress, http.StatusPermanentRedirect)
160161 }
161162