mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-27 12:25:55 +03:00
Merge pull request #50 from ChannelMeter/core/bind_address
core: Add the option to specify what address to bind on in Caddyfile
This commit is contained in:
commit
1e730a74a0
3 changed files with 19 additions and 0 deletions
|
@ -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},
|
||||
|
|
12
config/setup/bindhost.go
Normal file
12
config/setup/bindhost.go
Normal file
|
@ -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
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue