Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
e4643f04
Commit
e4643f04
authored
Aug 04, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core: Bind all listeners to wildcard host by default (closes #208)
This behavior can still be overridden by bind directive
parent
236c8c4e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
17 deletions
+14
-17
config/config.go
config/config.go
+0
-4
config/config_test.go
config/config_test.go
+9
-7
main.go
main.go
+5
-6
No files found.
config/config.go
View file @
e4643f04
...
...
@@ -182,11 +182,7 @@ func arrangeBindings(allConfigs []server.Config) (Group, error) {
// resolve, that host can still be served but will be listening on
// the wildcard host instead. This function takes care of this for you.
func
resolveAddr
(
conf
server
.
Config
)
(
resolvAddr
*
net
.
TCPAddr
,
warnErr
error
,
fatalErr
error
)
{
// The host to bind to may be different from the (virtual)host to serve
bindHost
:=
conf
.
BindHost
if
bindHost
==
""
{
bindHost
=
conf
.
Host
}
resolvAddr
,
warnErr
=
net
.
ResolveTCPAddr
(
"tcp"
,
net
.
JoinHostPort
(
bindHost
,
conf
.
Port
))
if
warnErr
!=
nil
{
...
...
config/config_test.go
View file @
e4643f04
...
...
@@ -22,13 +22,15 @@ func TestResolveAddr(t *testing.T) {
expectedIP
string
expectedPort
int
}{
{
server
.
Config
{
Host
:
"localhost"
,
Port
:
"1234"
},
false
,
false
,
"127.0.0.1"
,
1234
},
{
server
.
Config
{
Host
:
"127.0.0.1"
,
Port
:
"1234"
},
false
,
false
,
"127.0.0.1"
,
1234
},
{
server
.
Config
{
Host
:
"should-not-resolve"
,
Port
:
"1234"
},
true
,
false
,
"0.0.0.0"
,
1234
},
{
server
.
Config
{
Host
:
"localhost"
,
Port
:
"http"
},
false
,
false
,
"127.0.0.1"
,
80
},
{
server
.
Config
{
Host
:
"localhost"
,
Port
:
"https"
},
false
,
false
,
"127.0.0.1"
,
443
},
{
server
.
Config
{
Host
:
""
,
Port
:
"1234"
},
false
,
false
,
"<nil>"
,
1234
},
{
server
.
Config
{
Host
:
"localhost"
,
Port
:
"abcd"
},
false
,
true
,
""
,
0
},
{
server
.
Config
{
Host
:
"127.0.0.1"
,
Port
:
"1234"
},
false
,
false
,
"<nil>"
,
1234
},
{
server
.
Config
{
Host
:
"localhost"
,
Port
:
"80"
},
false
,
false
,
"<nil>"
,
80
},
{
server
.
Config
{
BindHost
:
"localhost"
,
Port
:
"1234"
},
false
,
false
,
"127.0.0.1"
,
1234
},
{
server
.
Config
{
BindHost
:
"127.0.0.1"
,
Port
:
"1234"
},
false
,
false
,
"127.0.0.1"
,
1234
},
{
server
.
Config
{
BindHost
:
"should-not-resolve"
,
Port
:
"1234"
},
true
,
false
,
"0.0.0.0"
,
1234
},
{
server
.
Config
{
BindHost
:
"localhost"
,
Port
:
"http"
},
false
,
false
,
"127.0.0.1"
,
80
},
{
server
.
Config
{
BindHost
:
"localhost"
,
Port
:
"https"
},
false
,
false
,
"127.0.0.1"
,
443
},
{
server
.
Config
{
BindHost
:
""
,
Port
:
"1234"
},
false
,
false
,
"<nil>"
,
1234
},
{
server
.
Config
{
BindHost
:
"localhost"
,
Port
:
"abcd"
},
false
,
true
,
""
,
0
},
{
server
.
Config
{
BindHost
:
"127.0.0.1"
,
Host
:
"should-not-be-used"
,
Port
:
"1234"
},
false
,
false
,
"127.0.0.1"
,
1234
},
{
server
.
Config
{
BindHost
:
"localhost"
,
Host
:
"should-not-be-used"
,
Port
:
"1234"
},
false
,
false
,
"127.0.0.1"
,
1234
},
{
server
.
Config
{
BindHost
:
"should-not-resolve"
,
Host
:
"localhost"
,
Port
:
"1234"
},
true
,
false
,
"0.0.0.0"
,
1234
},
...
...
main.go
View file @
e4643f04
...
...
@@ -87,14 +87,13 @@ func main() {
fmt
.
Printf
(
"Notice: %s is only accessible on this machine (%s)
\n
"
,
conf
.
Host
,
addr
.
IP
.
String
())
}
}
if
!
checkedFdLimit
&&
!
addr
.
IP
.
IsLoopback
()
{
if
!
checkedFdLimit
&&
!
addr
.
IP
.
IsLoopback
()
&&
!
isLocalhost
(
conf
.
Host
)
{
checkFdlimit
()
checkedFdLimit
=
true
}
}
}
}
// Wait for all listeners to stop
app
.
Wg
.
Wait
()
...
...
@@ -111,7 +110,7 @@ func checkFdlimit() {
// Note that an error here need not be reported
lim
,
err
:=
strconv
.
Atoi
(
string
(
bytes
.
TrimSpace
(
out
)))
if
err
==
nil
&&
lim
<
min
{
fmt
.
Printf
(
"Warning: File descriptor limit %d is too low for production sites.
\n
At least %d is recommended. Set with
\"
ulimit -n %d
\"
.
\n
"
,
lim
,
min
,
min
)
fmt
.
Printf
(
"Warning: File descriptor limit %d is too low for production sites.
At least %d is recommended. Set with
\"
ulimit -n %d
\"
.
\n
"
,
lim
,
min
,
min
)
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment