Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dualstack IPv6/IPv4 support #2266

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ For example, in case you want to run the app on port `5000`, just set the enviro

## Socket Binding

* `--host <str>` - Bind socket to this host. Use `--host 0.0.0.0` to make the application available on your local network. IPv6 addresses are supported, for example: `--host '::'`. **Default:** *'127.0.0.1'*.
* `--host <str>` - Bind socket to this host. May be used multiple times. If unused, then by default all interfaces are assumed and a list of multiple sockets will be used. Use `--host 127.0.0.1` to make the application available only on your local machine. IPv6 addresses are supported, for example: `--host '::'`. **Default:** *'auto'*.
* `--port <int>` - Bind to a socket with this port. **Default:** *8000*.
* `--uds <path>` - Bind to a UNIX domain socket, for example `--uds /tmp/uvicorn.sock`. Useful if you want to run Uvicorn behind a reverse proxy.
* `--fd <int>` - Bind to socket from this file descriptor. Useful if you want to run Uvicorn within a process manager.
Expand Down
2 changes: 1 addition & 1 deletion uvicorn/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class Config:
def __init__(
self,
app: ASGIApplication | Callable[..., Any] | str,
host: str = "127.0.0.1",
host: list[str] | str | None = None,
port: int = 8000,
uds: str | None = None,
fd: int | None = None,
Expand Down
6 changes: 2 additions & 4 deletions uvicorn/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,8 @@ def print_version(ctx: click.Context, param: click.Parameter, value: bool) -> No
@click.argument("app", envvar="UVICORN_APP")
@click.option(
"--host",
type=str,
default="127.0.0.1",
multiple=True,
help="Bind socket to this host.",
show_default=True,
)
@click.option(
"--port",
Expand Down Expand Up @@ -460,7 +458,7 @@ def main(
def run(
app: ASGIApplication | Callable[..., Any] | str,
*,
host: str = "127.0.0.1",
host: list[str] | str | None = None,
port: int = 8000,
uds: str | None = None,
fd: int | None = None,
Expand Down
2 changes: 1 addition & 1 deletion uvicorn/middleware/proxy_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ProxyHeadersMiddleware:
def __init__(
self,
app: ASGI3Application,
trusted_hosts: list[str] | str = "127.0.0.1",
trusted_hosts: list[str] | str | None = None,
) -> None:
self.app = app
if isinstance(trusted_hosts, str):
Expand Down
2 changes: 1 addition & 1 deletion uvicorn/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def _log_started_message(self, listeners: Sequence[socket.SocketType]) -> None:

else:
addr_format = "%s://%s:%d"
host = "0.0.0.0" if config.host is None else config.host
host = config.host
if ":" in host:
# It's an IPv6 address.
addr_format = "%s://[%s]:%d"
Expand Down