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
Log when auto HTTPS or auto HTTP->HTTPS redirects are disabled
Matthew Holt committed
Sep 9, 2019 at 08:25 UTC
9169cd43d49236c69d5c9b7c556cb0ac0c9ce497
2 files changed
+25
modules/caddyhttp/caddyhttp.go
+8
@@ -234,6 +234,8 @@ func (app *App) automaticHTTPS() error {
234
235
// skip if all listeners use the HTTP port
236
if !srv.listenersUseAnyPortOtherThan(app.HTTPPort) {
237
+ log.Printf("[INFO] Server %v is only listening on the HTTP port %d, so no automatic HTTPS will be applied to this server",
238
+ srv.Listen, app.HTTPPort)
239
continue
240
}
241
@@ -315,6 +317,12 @@ func (app *App) automaticHTTPS() error {
317
318
log.Printf("[INFO] Enabling automatic HTTP->HTTPS redirects for %v", domains)
319
320
+ // notify user if their config might override the HTTP->HTTPS redirects
321
+ if srv.listenersIncludePort(app.HTTPPort) {
322
+ log.Printf("[WARNING] Server %v is listening on HTTP port %d, so automatic HTTP->HTTPS redirects may be overridden by your own configuration",
323
+ srv.Listen, app.HTTPPort)
324
+ }
325
+
326
// create HTTP->HTTPS redirects
327
for _, addr := range srv.Listen {
328
netw, host, port, err := caddy.SplitListenAddr(addr)
modules/caddyhttp/server.go
+17
@@ -181,6 +181,23 @@ func (s *Server) listenersUseAnyPortOtherThan(otherPort int) bool {
181
return false
182
}
183
184
+// listenersIncludePort returns true if there are any
185
+// listeners in s that use otherPort.
186
+func (s *Server) listenersIncludePort(otherPort int) bool {
187
+ for _, lnAddr := range s.Listen {
188
+ _, addrs, err := caddy.ParseListenAddr(lnAddr)
189
+ if err == nil {
190
+ for _, a := range addrs {
191
+ _, port, err := net.SplitHostPort(a)
192
+ if err == nil && port == strconv.Itoa(otherPort) {
193
+ return true
194
+ }
195
+ }
196
+ }
197
+ }
198
+ return false
199
+}
200
+
201
func (s *Server) hasTLSClientAuth() bool {
202
for _, cp := range s.TLSConnPolicies {
203
if cp.ClientAuthentication != nil && cp.ClientAuthentication.Active() {