Skip to content

Commit

Permalink
httpcaddyfile: Add default_bind global option (#4531)
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie authored Jan 18, 2022
1 parent 93a7a45 commit 1b7ff5d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
6 changes: 5 additions & 1 deletion caddyconfig/httpcaddyfile/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ func (st *ServerType) listenerAddrsForServerBlockKey(sblock serverBlock, key str
lnHosts = append(lnHosts, cfgVal.Value.([]string)...)
}
if len(lnHosts) == 0 {
lnHosts = []string{""}
if defaultBind, ok := options["default_bind"].(string); ok {
lnHosts = []string{defaultBind}
} else {
lnHosts = []string{""}
}
}

// use a map to prevent duplication
Expand Down
1 change: 1 addition & 0 deletions caddyconfig/httpcaddyfile/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func init() {
RegisterGlobalOption("debug", parseOptTrue)
RegisterGlobalOption("http_port", parseOptHTTPPort)
RegisterGlobalOption("https_port", parseOptHTTPSPort)
RegisterGlobalOption("default_bind", parseOptSingleString)
RegisterGlobalOption("grace_period", parseOptDuration)
RegisterGlobalOption("default_sni", parseOptSingleString)
RegisterGlobalOption("order", parseOptOrder)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
default_bind tcp4/0.0.0.0
}

example.com {
}

example.org:12345 {
}
----------
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
"tcp4/0.0.0.0:12345"
],
"routes": [
{
"match": [
{
"host": [
"example.org"
]
}
],
"terminal": true
}
]
},
"srv1": {
"listen": [
"tcp4/0.0.0.0:443"
],
"routes": [
{
"match": [
{
"host": [
"example.com"
]
}
],
"terminal": true
}
]
}
}
}
}
}

0 comments on commit 1b7ff5d

Please sign in to comment.