> For the complete documentation index, see [llms.txt](https://docs.fivemstats.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fivemstats.net/tgiann-fivem-stats-script/https/cloudflare-tunnel.md).

# Cloudflare Tunnel

The easiest way to serve screenshots and videos from your own domain with HTTPS. Free, no ports to open.

Cloudflare Tunnel is the easiest way to put the media service on your own domain, for example `https://media.yourserver.com`. A small program (`cloudflared`) runs on your server and connects out to Cloudflare, so:

* HTTPS comes from Cloudflare, no certificate to manage.
* No inbound port has to be open, not even the media port or port 80.
* Your server's IP is not in the file links.

{% hint style="info" %}
Menu names below are from the Cloudflare dashboard on **24 October 2026**. Cloudflare moves menus now and then; if a name is different, find it with the dashboard search (**Ctrl K**).
{% endhint %}

## What you need

* A domain, bought anywhere (or in Cloudflare: **Domains** > **Buy domain**).
* A free [Cloudflare account](https://dash.cloudflare.com/sign-up).
* Administrator access to the machine FXServer runs on.

## 1. Add your domain to Cloudflare

Skip this step if the domain already shows **Active** under **Domains**.

1. In the [Cloudflare dashboard](https://dash.cloudflare.com) open **Domains** > **Overview** in the left menu and click **Add domain**.
2. Choose **Connect a domain**.
3. Enter your domain without `www` (`yourserver.com`) and continue.
4. Pick the **Free** plan.
5. Cloudflare lists the DNS records it found. Check them (your website, email) and continue.
6. Cloudflare shows **two nameservers**. Log in where you bought the domain and replace its nameservers with these two. If DNSSEC is on there, turn it off first; you can turn it on again in Cloudflare later.
7. Wait until the domain shows **Active** on the **Domains** page. It usually takes minutes, at most 24 hours, and Cloudflare sends an email when it is done.

## 2. Create the tunnel

1. Open **Networking** > **Tunnels** in the left menu and click **Create Tunnel**.
2. Enter a name, for example `fivem-server`, and click **Create Tunnel**.
3. Under **Operating System** choose **Windows**, under **Architecture** choose **64-bit**.
4. Click the `cloudflared-windows-amd64.msi` link on the page and run the installer.
5. Open **Command Prompt as Administrator**: press Start, type `cmd`, right click **Command Prompt** > **Run as administrator**.
6. Copy the command on the page with its copy button and run it. It looks like this, with your own long token:

```bat
cloudflared.exe service install eyJhIjoi...
```

7. **Connection Status** changes from "No connection detected yet" to connected. Click **Continue**.

`cloudflared` is now a Windows service: it starts with Windows, you do not need to keep a window open.

{% hint style="danger" %}
The token in the command gives access to your Cloudflare account. Never share it or post it in a screenshot. If it leaks, delete the tunnel and create a new one.
{% endhint %}

On a **Linux** server choose **Debian** or **Red Hat** instead and run the commands the page shows.

## 3. Send a subdomain to the media service

1. Open **Networking** > **Tunnels** and click your tunnel's name.
2. Open the **Routes** tab, click **Add route** and choose **Published application**.
3. Fill in:

| Field           | Value                   |
| --------------- | ----------------------- |
| **Subdomain**   | `media`                 |
| **Domain**      | `yourserver.com`        |
| **Path**        | Leave empty             |
| **Service URL** | `http://localhost:6174` |

4. Click **Add route**.

`6174` is the media port; use your own if you changed `tgiann_media_port`. Cloudflare creates the DNS record by itself: under the domain's **DNS** > **Records** you now see `media.yourserver.com` with type **Tunnel** and **Proxied**.

{% hint style="warning" %}
Use a subdomain one level deep, like `media.yourserver.com`. Deeper names (`media.fivem.yourserver.com`) need a paid certificate in Cloudflare.
{% endhint %}

## 4. server.cfg

```cfg
set tgiann_media_https "off"
# optional: only cloudflared on this machine can reach the service
set tgiann_media_host "127.0.0.1"

ensure tgiann-fivem-stats-script
```

* `off`: Cloudflare already adds HTTPS, so the service does not need its own certificate or port 80.
* `127.0.0.1`: the service only answers this machine. You can then close the media port in your firewall. Links handed out earlier with your IP stop working; leave this line out if old links (a phone gallery, MDT photos) must keep working.

Restart the resource: `ensure tgiann-fivem-stats-script`.

## 5. Enter the address in the panel

In the panel open **Settings** > **Media storage** > **Public address**, enter `https://media.yourserver.com` (no `/` at the end) and click **Save changes**. New links use it at once. See [Settings > Media storage](https://docs.fivemstats.net/panel/settings.md#media-storage).

## 6. Check it

1. Open `https://media.yourserver.com/health` in a browser. It answers `"status":"ok"` and `publicUrl` is your domain.
2. Run `/mediatest` in game. The link it prints starts with `https://media.yourserver.com`.
3. The [Media](https://docs.fivemstats.net/panel/media.md) page shows the thumbnails.

## Limits and problems

{% hint style="warning" %}
Cloudflare's Free and Pro plans accept uploads up to **100 MB** per file through the tunnel. Screenshots and normal clips fit; a larger video upload fails with `413`. Downloads have no such limit.
{% endhint %}

| Problem                                                       | Fix                                                                                                             |
| ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| The tunnel shows **Down** under **Networking** > **Tunnels**  | The `cloudflared` service is not running. Open **Services** in Windows, find **Cloudflared agent** and start it |
| The tunnel is up but the domain shows a Cloudflare error page | The **Service URL** port does not match `tgiann_media_port`, or the resource is stopped                         |
| The tunnel never connects                                     | The server must reach Cloudflare outbound on port `7844`. Most hosts allow it; ask yours if not                 |
| Links still show the IP                                       | **Public address** is empty or not saved, see step 5                                                            |

Other ways to get HTTPS (an automatic certificate for the IP, your own certificate, nginx): [HTTPS](https://docs.fivemstats.net/tgiann-fivem-stats-script/https.md).
