From e4643f048af7b15bd781b92585b1ac930a1a09c2 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 4 Aug 2015 18:29:54 -0600 Subject: [PATCH] core: Bind all listeners to wildcard host by default (closes #208) This behavior can still be overridden by bind directive --- config/config.go | 4 ---- config/config_test.go | 16 +++++++++------- main.go | 11 +++++------ 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/config/config.go b/config/config.go index ae11b4bc..3037a267 100644 --- a/config/config.go +++ b/config/config.go @@ -182,11 +182,7 @@ func arrangeBindings(allConfigs []server.Config) (Group, error) { // resolve, that host can still be served but will be listening on // the wildcard host instead. This function takes care of this for you. func resolveAddr(conf server.Config) (resolvAddr *net.TCPAddr, warnErr error, fatalErr error) { - // The host to bind to may be different from the (virtual)host to serve bindHost := conf.BindHost - if bindHost == "" { - bindHost = conf.Host - } resolvAddr, warnErr = net.ResolveTCPAddr("tcp", net.JoinHostPort(bindHost, conf.Port)) if warnErr != nil { diff --git a/config/config_test.go b/config/config_test.go index a2f9bdd0..75678419 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -22,13 +22,15 @@ func TestResolveAddr(t *testing.T) { expectedIP string expectedPort int }{ - {server.Config{Host: "localhost", Port: "1234"}, false, false, "127.0.0.1", 1234}, - {server.Config{Host: "127.0.0.1", Port: "1234"}, false, false, "127.0.0.1", 1234}, - {server.Config{Host: "should-not-resolve", Port: "1234"}, true, false, "0.0.0.0", 1234}, - {server.Config{Host: "localhost", Port: "http"}, false, false, "127.0.0.1", 80}, - {server.Config{Host: "localhost", Port: "https"}, false, false, "127.0.0.1", 443}, - {server.Config{Host: "", Port: "1234"}, false, false, "", 1234}, - {server.Config{Host: "localhost", Port: "abcd"}, false, true, "", 0}, + {server.Config{Host: "127.0.0.1", Port: "1234"}, false, false, "", 1234}, + {server.Config{Host: "localhost", Port: "80"}, false, false, "", 80}, + {server.Config{BindHost: "localhost", Port: "1234"}, false, false, "127.0.0.1", 1234}, + {server.Config{BindHost: "127.0.0.1", Port: "1234"}, false, false, "127.0.0.1", 1234}, + {server.Config{BindHost: "should-not-resolve", Port: "1234"}, true, false, "0.0.0.0", 1234}, + {server.Config{BindHost: "localhost", Port: "http"}, false, false, "127.0.0.1", 80}, + {server.Config{BindHost: "localhost", Port: "https"}, false, false, "127.0.0.1", 443}, + {server.Config{BindHost: "", Port: "1234"}, false, false, "", 1234}, + {server.Config{BindHost: "localhost", Port: "abcd"}, false, true, "", 0}, {server.Config{BindHost: "127.0.0.1", Host: "should-not-be-used", Port: "1234"}, false, false, "127.0.0.1", 1234}, {server.Config{BindHost: "localhost", Host: "should-not-be-used", Port: "1234"}, false, false, "127.0.0.1", 1234}, {server.Config{BindHost: "should-not-resolve", Host: "localhost", Port: "1234"}, true, false, "0.0.0.0", 1234}, diff --git a/main.go b/main.go index 51ffa064..947548a5 100644 --- a/main.go +++ b/main.go @@ -87,11 +87,10 @@ func main() { fmt.Printf("Notice: %s is only accessible on this machine (%s)\n", conf.Host, addr.IP.String()) } - } - - if !checkedFdLimit && !addr.IP.IsLoopback() { - checkFdlimit() - checkedFdLimit = true + if !checkedFdLimit && !addr.IP.IsLoopback() && !isLocalhost(conf.Host) { + checkFdlimit() + checkedFdLimit = true + } } } } @@ -111,7 +110,7 @@ func checkFdlimit() { // Note that an error here need not be reported lim, err := strconv.Atoi(string(bytes.TrimSpace(out))) if err == nil && lim < min { - fmt.Printf("Warning: File descriptor limit %d is too low for production sites.\nAt least %d is recommended. Set with \"ulimit -n %d\".\n", lim, min, min) + fmt.Printf("Warning: File descriptor limit %d is too low for production sites. At least %d is recommended. Set with \"ulimit -n %d\".\n", lim, min, min) } } }