# Installing & Troubleshooting LibreSpeed on CasaOS

**Objective:** Set up a self-hosted LibreSpeed server on CasaOS to perform local network speed tests, bypassing internet variables to test actual LAN/Wi-Fi throughput.

**Environment:**

- **Host OS:** Ubuntu Server
- **Management UI:** CasaOS
- **Application:** LibreSpeed (`ghcr.io/librespeed/speedtest`)

---

## Part 1: Installation via CasaOS

Since port 80 is often occupied by other services (like Nginx Proxy Manager), this guide uses port **8082** for the host interface.

### Method A: YAML Import (Recommended &amp; Fastest)

1. Open your **CasaOS Dashboard**.
2. Click the **App Store** icon, then click **Custom Install** in the top right corner.
3. Click the **Import** icon (document with an arrow) in the upper right.
4. Paste the following configuration: ```
    services:
      librespeed:
        image: ghcr.io/librespeed/speedtest
        container_name: librespeed
        ports:
          - "8082:8080"
        environment:
          - MODE=standalone
          - TELEMETRY=false
        restart: always
    ```
5. Click **Next**, verify the auto-filled settings, and click **Install**.

### Method B: Manual Configuration

If manually entering the details in the **Custom Install** menu, use the following parameters:

- **Docker Image:** `ghcr.io/librespeed/speedtest`
- **Title:** `LibreSpeed`
- **Web UI:** `http://[Server_IP]:8082/`
- **Port:** Host `8082` | Container `8080` | Protocol `TCP`
- **Environment Variables:**
    - Key: `MODE` | Value: `standalone`
    - Key: `TELEMETRY` | Value: `false`

---

## Part 2: Troubleshooting "Connection Refused"

If you attempt to access `http://<Server_IP>:8082` and receive a **"This site can’t be reached / Connection Refused"** error, follow these diagnostic steps.

### Step 1: Verify Host Firewall (UFW) Status

Ubuntu's Uncomplicated Firewall (UFW) may block newly assigned ports. Check and open the port using the terminal:

```
sudo ufw allow 8082/tcp
sudo ufw reload
```

*(Note: If the terminal returns `Firewall not enabled (skipping reload)UFW is turned off and is not the cause of the blockage.`*

### Step 2: Test Local Container Connectivity

Determine if the container is actively listening on the host by running a local HTTP header request from the server terminal:

```
curl -I http://localhost:8082
```

- **Result `HTTP/1.1 200 OK`:** The container is functioning properly. The issue is likely due to a network-wide firewall or router isolation.
- **Result `Connection reset by peer`**The container is receiving the request, but the internal application is crashing or rejecting the traffic. Proceed to Step 3.

### Step 3: Inspect Container Logs for Internal Port Binding

If the connection is being reset by the peer, the internal application inside the Docker container is likely misconfigured.

1. In CasaOS, click the three dots (**⋮**) on the LibreSpeed app and select **Settings**.
2. Click the **Terminal/Logs** icon (`>_`) in the top right and view the **Logs** tab.
3. Look for the Apache port configuration sequence. You may see lines like this:

```
+ '[' 8080 '!=' 80 ']'
+ sed -i 's/^Listen 80$/Listen 8080/g' /etc/apache2/ports.conf
+ sed -i 's/*:80>/*:8080>/g' /etc/apache2/sites-available/000-default.conf
```

**The Root Cause:** Recent versions of the `ghcr.io/librespeed/speedtest` Image has updated its internal Apache web server to listen on port `8080` by default, rather than the standard port `80`. If CasaOS is configured to route traffic to the container port `80The traffic hits a dead end, resulting in the "Connection reset by peer" error.`

**The Fix:**

1. Open the LibreSpeed **Settings** in CasaOS.
2. Scroll to the **Port** section.
3. Change the **Container** port from `80` to **`8080`**.
4. Click **Save** to restart the container with the correct mapping.