mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-13 22:51:08 -05:00
core: add bindaddr directive, allowing you to specify what address to listen on
This commit is contained in:
parent
2dbd14b6dc
commit
d3aedbeb9a
3 changed files with 19 additions and 0 deletions
|
@ -43,6 +43,7 @@ var directiveOrder = []directive{
|
||||||
// Essential directives that initialize vital configuration settings
|
// Essential directives that initialize vital configuration settings
|
||||||
{"root", setup.Root},
|
{"root", setup.Root},
|
||||||
{"tls", setup.TLS},
|
{"tls", setup.TLS},
|
||||||
|
{"bindaddr", setup.BindAddr},
|
||||||
|
|
||||||
// Other directives that don't create HTTP handlers
|
// Other directives that don't create HTTP handlers
|
||||||
{"startup", setup.Startup},
|
{"startup", setup.Startup},
|
||||||
|
|
12
config/setup/bindaddr.go
Normal file
12
config/setup/bindaddr.go
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
package setup
|
||||||
|
|
||||||
|
import "github.com/mholt/caddy/middleware"
|
||||||
|
|
||||||
|
func BindAddr(c *Controller) (middleware.Middleware, error) {
|
||||||
|
for c.Next() {
|
||||||
|
if !c.Args(&c.BindAddress) {
|
||||||
|
return nil, c.ArgErr()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
|
}
|
|
@ -11,6 +11,9 @@ type Config struct {
|
||||||
// The hostname or IP on which to serve
|
// The hostname or IP on which to serve
|
||||||
Host string
|
Host string
|
||||||
|
|
||||||
|
// The address to bind on - defaults to Host if empty
|
||||||
|
BindAddress string
|
||||||
|
|
||||||
// The port to listen on
|
// The port to listen on
|
||||||
Port string
|
Port string
|
||||||
|
|
||||||
|
@ -44,6 +47,9 @@ type Config struct {
|
||||||
|
|
||||||
// Address returns the host:port of c as a string.
|
// Address returns the host:port of c as a string.
|
||||||
func (c Config) Address() string {
|
func (c Config) Address() string {
|
||||||
|
if c.BindAddress != "" {
|
||||||
|
return net.JoinHostPort(c.BindAddress, c.Port)
|
||||||
|
}
|
||||||
return net.JoinHostPort(c.Host, c.Port)
|
return net.JoinHostPort(c.Host, c.Port)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue