Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vitepress/config.v3.mts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const v3: DefaultTheme.Config = {
{ text: 'Idle Connection Timeout', link: '/v3/features/idle-timeout' },
{ text: 'Maximum Connections', link: '/v3/features/max-connections' },
{ text: 'Maximum Request Header Size', link: '/v3/features/max-header-size' },
{ text: 'IPv6-Only Host', link: '/v3/features/ipv6-only' },
{ text: 'File Descriptor Socket Passing', link: '/v3/features/file-descriptor-socket-passing' },
{ text: 'Unix Domain Socket', link: '/v3/features/unix-domain-socket' },
{ text: 'Worker Threads Customization', link: '/v3/features/worker-threads' },
Expand Down
4 changes: 3 additions & 1 deletion src/v3/configuration/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ Commands:

Options:
-a, --host <HOST>
Host address (E.g 127.0.0.1 or ::1). The default `::` accepts both IPv6 and IPv4 connections where the OS supports dual-stack sockets [env: SERVER_HOST=] [default: ::]
Host address (E.g 127.0.0.1 or ::1). The default `::` accepts both IPv6 and IPv4 connections where the OS supports dual-stack sockets, unless `--ipv6-only` is enabled [env: SERVER_HOST=] [default: ::]
--ipv6-only [<IPV6_ONLY>]
Make the unspecified IPv6 host `::` accept IPv6 connections only, leaving the port free for IPv4. It has no effect on a specific IPv6 host and cannot be used with an IPv4 host, `--fd` or `--unix-socket` [env: SERVER_IPV6_ONLY=] [default: false] [possible values: true, false]
-p, --port <PORT>
Host port [env: SERVER_PORT=] [default: 8080]
--open [<OPEN>]
Expand Down
6 changes: 5 additions & 1 deletion src/v3/configuration/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ The server can be configured via the following environment variables.

## SERVER_HOST

Host address (e.g. `127.0.0.1` or `::1`). The default `::` accepts both IPv6 and IPv4 connections where the OS supports dual-stack sockets. Default `::`.
Host address (e.g. `127.0.0.1` or `::1`). The default `::` accepts both IPv6 and IPv4 connections where the OS supports dual-stack sockets, unless `SERVER_IPV6_ONLY` is enabled. Default `::`.

## SERVER_IPV6_ONLY

Make the unspecified IPv6 host `::` accept IPv6 connections only, leaving the port free for IPv4. It has no effect on a specific IPv6 host and cannot be used with an IPv4 host, `SERVER_LISTEN_FD` or `SERVER_UNIX_SOCKET`. See [IPv6-Only Host](../features/ipv6-only.md). Default `false` (disabled).

## SERVER_PORT

Expand Down
1 change: 1 addition & 0 deletions src/v3/configuration/file.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Below is just an example showing all features with their default values.

#### Address & Root dir
host = "::"
ipv6-only = false
port = 8080
root = "."

Expand Down
1 change: 1 addition & 0 deletions src/v3/defaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ When running `static-web-server` with no flags, you get:
| Setting | Default | Rationale |
| ----------------------- | --------------------------------- | -------------------------------------------------------------------------------- |
| Host | `::` (all interfaces, dual-stack) | Reachable from any network interface, over IPv6 and IPv4 where the OS allows it. |
| IPv6 only | disabled | `::` also accepts IPv4 by default; `--ipv6-only` leaves the IPv4 port free. |
| Port | `8080` | Non-privileged port, no `root` needed. |
| Unix socket | disabled | TCP is the common case; UDS is opt-in for reverse-proxy setups. |
| File descriptor passing | disabled | Only needed in inetd/systemd/launchd sandboxing scenarios. |
Expand Down
2 changes: 2 additions & 0 deletions src/v3/features/cors.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ static-web-server \
# --cors-allow-origins "*"
```

Responses to requests with an allowed `Origin` header include `Origin` in the `Vary` header, so shared caches store a response per origin. SWS appends it to any `Vary` values already set, such as `Accept` on [automatic directory listings](./directory-listing.md#automatic-format), so caches still store each listing format separately.

## Allowed headers

The server also supports a list of [CORS allowed headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers) separated by commas.
Expand Down
24 changes: 24 additions & 0 deletions src/v3/features/ipv6-only.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# IPv6-Only Host

**SWS** binds the default `::` host as a dual-stack socket, so it accepts IPv6 and IPv4 connections and also takes the port for IPv4.

The `--ipv6-only` option or its equivalent [SERVER_IPV6_ONLY](./../configuration/env.md#server-ipv6-only) env makes `::` accept IPv6 connections only and leaves the port free for IPv4, for example for another service listening on `0.0.0.0` at the same port. It is disabled by default.

```sh
static-web-server -d ./public/ --ipv6-only
```

Or in the [configuration file](./../configuration/file.md):

```toml
[general]
host = "::"
ipv6-only = true
```

## Behavior

- The option applies to the main listener and the [HTTP to HTTPS redirect](./http-https-redirect.md) listener.
- SWS fails to start if the OS refuses to make the socket IPv6-only.
- A specific IPv6 host, such as `::1`, always accepts IPv6 connections only, so the option has no effect on it.
- SWS fails to start when the option is combined with an IPv4 host, such as `0.0.0.0`, with [file descriptor socket passing](./file-descriptor-socket-passing.md) (`--fd`) or with a [Unix domain socket](./unix-domain-socket.md) (`--unix-socket`).
1 change: 1 addition & 0 deletions src/v3/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ SWS is designed to be **simple by default, powerful when needed**. You can point
| [**Maximum Request Header Size**](./features/max-header-size) | Reject requests whose headers are larger than a configurable limit. |
| [**Windows Service**](./features/windows-service) | Install SWS as a native Windows Service with `sc` or the installer. |
| [**Docker**](./features/docker) | Official images on `scratch`, `Alpine`, and `Debian` for several architectures. |
| [**IPv6-Only Host**](./features/ipv6-only) | Keep the default `::` host IPv6-only and leave the port free for IPv4. |
| [**Unix Domain Socket**](./features/unix-domain-socket) | Listen on a UDS path for secure, low-latency local proxying. |
| [**File Descriptor Socket Passing**](./features/file-descriptor-socket-passing) | Pass a pre-opened socket via FD for seamless hot-reload setups. |
| [**Worker Threads**](./features/worker-threads) | Tune the thread pool to balance latency and throughput. |
Expand Down
4 changes: 2 additions & 2 deletions src/v3/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ With `--page-fallback`, requests for missing assets (e.g. `/favicon.ico` or a sc

v3 binds the default `--host ::` as a dual-stack socket, so it accepts IPv4 too on Windows, FreeBSD and Linux with `net.ipv6.bindv6only=1`, where v2 listened on IPv6 only. It then also reserves the port for IPv4.

**Action:** If another service listens on `0.0.0.0` at the same port, SWS now fails with "address in use": change one of the ports, or bind SWS to a specific IPv6 address to stay IPv6-only.
**Action:** If another service listens on `0.0.0.0` at the same port, SWS now fails with "address in use": change one of the ports, or add `--ipv6-only` to keep `::` IPv6-only as in v2. See [IPv6-Only Host](./features/ipv6-only.md).

## Quick migration checklist

Expand All @@ -192,4 +192,4 @@ v3 binds the default `--host ::` as a dual-stack socket, so it accepts IPv4 too
13. **Header size:** Raise `--max-header-size` if clients send headers over 16 KiB.
14. **Cache-Control:** No action needed. HTML now gets `no-cache`.
15. **Fallback page:** No action needed. Missing assets keep their `404`.
16. **Dual-stack:** Make sure no other service uses the same port on `0.0.0.0`.
16. **Dual-stack:** Make sure no other service uses the same port on `0.0.0.0`, or add `--ipv6-only`.