diff options
author | Matt Holt <[email protected]> | 2015-05-05 00:05:42 -0600 |
---|---|---|
committer | Matt Holt <[email protected]> | 2015-05-05 00:05:42 -0600 |
commit | 1e730a74a031bceef77408e004bc8d75d396e305 (patch) | |
tree | 7007acd2648912dd3a3159a5681de89a8c863a79 | |
parent | 4637f14b7f3cbe832717abbfab2a7a14383e0b65 (diff) | |
parent | 46f7930787aed2b133248ad89dd4c750ed6ed4fc (diff) | |
download | caddy-1e730a74a031bceef77408e004bc8d75d396e305.tar.gz caddy-1e730a74a031bceef77408e004bc8d75d396e305.zip |
Merge pull request #50 from ChannelMeter/core/bind_address
core: Add the option to specify what address to bind on in Caddyfile
-rw-r--r-- | config/directives.go | 1 | ||||
-rw-r--r-- | config/setup/bindhost.go | 12 | ||||
-rw-r--r-- | server/config.go | 6 |
3 files changed, 19 insertions, 0 deletions
diff --git a/config/directives.go b/config/directives.go index 679ea5ea2..fe9a9f929 100644 --- a/config/directives.go +++ b/config/directives.go @@ -43,6 +43,7 @@ var directiveOrder = []directive{ // Essential directives that initialize vital configuration settings {"root", setup.Root}, {"tls", setup.TLS}, + {"bind", setup.BindHost}, // Other directives that don't create HTTP handlers {"startup", setup.Startup}, diff --git a/config/setup/bindhost.go b/config/setup/bindhost.go new file mode 100644 index 000000000..3e4bf89b3 --- /dev/null +++ b/config/setup/bindhost.go @@ -0,0 +1,12 @@ +package setup + +import "github.com/mholt/caddy/middleware" + +func BindHost(c *Controller) (middleware.Middleware, error) { + for c.Next() { + if !c.Args(&c.BindHost) { + return nil, c.ArgErr() + } + } + return nil, nil +} diff --git a/server/config.go b/server/config.go index 591f9a48c..b037b613c 100644 --- a/server/config.go +++ b/server/config.go @@ -11,6 +11,9 @@ type Config struct { // The hostname or IP on which to serve Host string + // The host address to bind on - defaults to (virtual) Host if empty + BindHost string + // The port to listen on Port string @@ -44,6 +47,9 @@ type Config struct { // Address returns the host:port of c as a string. func (c Config) Address() string { + if c.BindHost != "" { + return net.JoinHostPort(c.BindHost, c.Port) + } return net.JoinHostPort(c.Host, c.Port) } |