caddy-website/src/docs/markdown/caddyfile/directives/bind.md

42 lines
1.2 KiB
Markdown
Raw Normal View History

2020-01-24 12:47:52 -07:00
---
title: bind (Caddyfile directive)
---
# bind
Overrides the interface to which the server's socket should bind. Normally, the listener binds to the empty (wildcard) interface. However, you may force the listener to bind to another hostname or IP instead. (This directive accepts only a host, not a port.)
2020-01-24 12:47:52 -07:00
Note that binding sites inconsistently may result in unintended consequences. For example, if two sites on the same port resolve to `127.0.0.1` and only one of those sites is configured with `bind 127.0.0.1`, then only one site will be accessible since the other will bind to the port without a specific host; the OS will choose the more specific matching socket. (Virtual hosts are not shared across different listeners.)
2020-01-24 12:47:52 -07:00
`bind` accepts [network addresses](/docs/conventions#network-addresses), but may not include a port.
2020-01-24 12:47:52 -07:00
## Syntax
```caddy-d
2020-01-24 12:47:52 -07:00
bind <hosts...>
```
- **&lt;hosts...&gt;** is the list of host interfaces to bind which to bind the listener.
2020-01-24 12:47:52 -07:00
## Examples
To make a socket accessible only on the current machine, bind to the loopback interface (localhost):
```caddy-d
2020-01-24 12:47:52 -07:00
bind 127.0.0.1
```
To include IPv6:
```caddy-d
bind 127.0.0.1 [::1]
2020-01-24 12:47:52 -07:00
```
To bind to a Unix domain socket at `/run/caddy`:
```caddy-d
bind unix//run/caddy
```