mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
core: Bind all listeners to wildcard host by default (closes #208)
This behavior can still be overridden by bind directive
This commit is contained in:
parent
236c8c4eaf
commit
e4643f048a
3 changed files with 14 additions and 17 deletions
|
@ -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 {
|
||||
|
|
|
@ -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, "<nil>", 1234},
|
||||
{server.Config{Host: "localhost", Port: "abcd"}, false, true, "", 0},
|
||||
{server.Config{Host: "127.0.0.1", Port: "1234"}, false, false, "<nil>", 1234},
|
||||
{server.Config{Host: "localhost", Port: "80"}, false, false, "<nil>", 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, "<nil>", 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},
|
||||
|
|
11
main.go
11
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue