# Host a dedicated Horizon server for browser players

Run the Horizon Rust server, this gateway, and Caddy on the same computer or VPS. The gateway forwards Minecraft packets to a local server on port 25565. Players can join from the Horizon site using HTTPS or WebSockets.

## 1. Start the game server

Install Horizon Server for Minecraft Java 26.3 and prepare or import your game resources as described in the [Horizon hosting guide](https://github.com/horizon-rust/horizon/blob/main/docs/hosting.md). Open a terminal in a new server folder and run:

```sh
horizon-server init
```

In the existing `[server]` section of `server.toml`, set:

```toml
bind = "127.0.0.1"
port = 25565
online_mode = false
whitelist = true
enforce_whitelist = true
```

This web build uses offline player profiles. Keep the Minecraft port bound to loopback and share the gateway key only with trusted players. A whitelist limits the permitted names in offline mode. Keep operator access on the server console.

```sh
horizon-server whitelist add PlayerName
horizon-server start
```

Use the player's name from **Edit Profile** in Horizon Web.

## 2. Start the gateway

Install the [current .NET 10 SDK](https://dotnet.microsoft.com/download/dotnet/10.0). Open a terminal in this folder and set `HORIZON_WEB_ORIGIN` to the address that actually serves Horizon Web, including `https://` and excluding any path or trailing slash. Generate a private key once and reuse it when you restart the gateway.

PowerShell 7:

```powershell
$env:HORIZON_WEB_ORIGIN = "https://your-site.example"
$env:HORIZON_JOIN_KEY = [Convert]::ToHexString([Security.Cryptography.RandomNumberGenerator]::GetBytes(32)).ToLowerInvariant()
dotnet run --configuration Release --no-launch-profile
```

Linux or macOS:

```sh
export HORIZON_WEB_ORIGIN="https://your-site.example"
export HORIZON_JOIN_KEY="$(openssl rand -hex 32)"
dotnet run --configuration Release --no-launch-profile
```

The gateway listens on `127.0.0.1:8089`. Save your generated key privately. Anyone who has it can use the gateway, subject to the server's whitelist.

## 3. Give the gateway an HTTPS hostname

Point a DNS name such as `mc.your-domain.example` at the host. Allow TCP 80 and 443 to reach [Caddy](https://caddyserver.com/docs/install). In a separate terminal in this folder, set `HORIZON_GATEWAY_DOMAIN` to that hostname and start Caddy:

```powershell
$env:HORIZON_GATEWAY_DOMAIN = "mc.your-domain.example"
caddy run --config Caddyfile
```

On Linux or macOS, use `export HORIZON_GATEWAY_DOMAIN=mc.your-domain.example`. Caddy provisions the HTTPS certificate and forwards the gateway requests. Ports 8089 and 25565 stay local.

If you already host this gateway, restart it with the updated code and reload Caddy with the updated Caddyfile. Custom reverse proxy configurations need to forward `/minecraft`, `/minecraft/http` and its subpaths, including `OPTIONS` requests.

## 4. Join from the website

In Horizon Web, open **Multiplayer** and choose **Horizon / Java gateway**. Enter the HTTPS link with your domain and key, then choose **Join server**.

```text
https://mc.your-domain.example/minecraft?invite=YOUR_KEY
```

The HTTPS link uses ordinary HTTPS requests between the browser and the gateway. The game uses your dedicated Rust server’s world. Your network still needs to allow access to the gateway’s HTTPS hostname.

The same gateway also accepts WebSocket links.

```text
wss://mc.your-domain.example/minecraft?invite=YOUR_KEY
```

**Copy server link** creates a link a friend can open in Horizon. It carries the gateway key, so share it privately. The launcher keeps the full endpoint in the URL fragment. For HTTPS connections it sends the key to the gateway in an Authorization header.

## Connection recovery

If a WebSocket gateway link fails to open, Horizon tries HTTPS once at the same host and port with the same invite key. An HTTPS invite starts directly over HTTPS.

If the connection drops during play, use **Reconnect** to start a fresh login. The gateway closes interrupted streams. HTTPS sessions expire after 40 seconds of inactivity, and the gateway shares a limit of 32 active connections across HTTPS and WebSockets.
