@marcel91200 / caddy Mirror · read-only / commits / 1b7ff5d7
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 13, 23:00 UTC

httpcaddyfile: Add `default_bind` global option (#4531)

Francis Lavoie committed Jan 18, 2022 at 13:29 UTC 1b7ff5d76c7a3c67b6e0f9b51af78d1b227fdea3
3 files changed +58 -1
caddyconfig/httpcaddyfile/addresses.go
+5 -1
@@ -213,7 +213,11 @@ func (st *ServerType) listenerAddrsForServerBlockKey(sblock serverBlock, key str
213 lnHosts = append(lnHosts, cfgVal.Value.([]string)...)
214 }
215 if len(lnHosts) == 0 {
216 - lnHosts = []string{""}
216 + if defaultBind, ok := options["default_bind"].(string); ok {
217 + lnHosts = []string{defaultBind}
218 + } else {
219 + lnHosts = []string{""}
220 + }
221 }
222
223 // use a map to prevent duplication
caddyconfig/httpcaddyfile/options.go
+1
@@ -29,6 +29,7 @@ func init() {
29 RegisterGlobalOption("debug", parseOptTrue)
30 RegisterGlobalOption("http_port", parseOptHTTPPort)
31 RegisterGlobalOption("https_port", parseOptHTTPSPort)
32 + RegisterGlobalOption("default_bind", parseOptSingleString)
33 RegisterGlobalOption("grace_period", parseOptDuration)
34 RegisterGlobalOption("default_sni", parseOptSingleString)
35 RegisterGlobalOption("order", parseOptOrder)
caddytest/integration/caddyfile_adapt/global_options_default_bind.txt new
+52
@@ -0,0 +1,52 @@
1 +{
2 + default_bind tcp4/0.0.0.0
3 +}
4 +
5 +example.com {
6 +}
7 +
8 +example.org:12345 {
9 +}
10 +----------
11 +{
12 + "apps": {
13 + "http": {
14 + "servers": {
15 + "srv0": {
16 + "listen": [
17 + "tcp4/0.0.0.0:12345"
18 + ],
19 + "routes": [
20 + {
21 + "match": [
22 + {
23 + "host": [
24 + "example.org"
25 + ]
26 + }
27 + ],
28 + "terminal": true
29 + }
30 + ]
31 + },
32 + "srv1": {
33 + "listen": [
34 + "tcp4/0.0.0.0:443"
35 + ],
36 + "routes": [
37 + {
38 + "match": [
39 + {
40 + "host": [
41 + "example.com"
42 + ]
43 + }
44 + ],
45 + "terminal": true
46 + }
47 + ]
48 + }
49 + }
50 + }
51 + }
52 +}
\ No newline at end of file