Skip to content

Set Up Cloudflare Tunnel (cloudflared) on a Linux Server – Publish Services Without Open Ports

Set up Cloudflare Tunnel on a Linux server: cloudflared as a One-Click App or with Docker Compose, add your token, publish services without open ports.

29 November 202613 min read1 Views0 helpful

Introduction

cloudflared is the program behind Cloudflare Tunnel. It establishes an encrypted, outbound connection from your VPS to Cloudflare. Cloudflare uses this connection to forward requests to your domain to services on your server, such as a web interface on port 8080. You don't need to open any inbound ports, and your VPS's IP address doesn't appear in your domain's DNS. Cloudflare provides the HTTPS certificate, so you don't need your own reverse proxy for these addresses.

In this guide, we'll show you two ways to set it up: the easy way as a One-Click App, where you only need to enter the tunnel token, and a manual installation with Docker Compose. Then, you'll publish a service on the same VPS under your domain and, if you want, protect it with a sign-in through Cloudflare Access.

Info: General tunnel, not a txAdmin-specific case

This guide covers cloudflared in general for any web services on your VPS. If you only want to secure the txAdmin interface of a FiveM server, follow the guide Set up Cloudflare Tunnel for txAdmin. For information on connecting a domain from ZAP-Hosting to Cloudflare, see Set up a domain with Cloudflare.

When a Cloudflare Tunnel makes sense on a VPS

A tunnel is especially useful for web interfaces that you want to access under your own domain without exposing them directly to the internet. On a VPS, cloudflared is a good fit if:

  • you don't want to open ports for web services. The service listens only locally, the firewall stays closed, and it's still accessible through your domain.
  • you don't want your server's IP address to appear in DNS. Your domain points to Cloudflare, not to the VPS.
  • you want to protect admin interfaces further. With Cloudflare Access, Cloudflare asks you to sign in before access, for example by sending a one-time code to your email address.
  • you want to run multiple services on subdomains without managing nginx, certificates, and DNS records for each service yourself.
  • you want to put services behind Cloudflare's protection for web requests, such as firewall rules and rate limiting for your Cloudflare zone.

A tunnel is less suitable for game servers and anything that players or clients need to access directly over TCP or UDP. Only web services (HTTP and HTTPS) work publicly in a browser. For SSH, RDP, or other TCP services, users need cloudflared or the WARP client themselves. Large uploads can also run into limits because Cloudflare restricts the size of an individual request. And because HTTPS terminates at Cloudflare, your traffic passes through Cloudflare's network unencrypted.

Cloudflare Tunnel or your own domain with a reverse proxy?

Many One-Click Apps are already accessible via HTTPS under a subdomain without a tunnel. A tunnel is an addition, not a requirement:

Cloudflare TunnelOne-Click App subdomain or your own reverse proxy
Inbound portsnone80 and 443 open
DNS points toCloudflareyour VPS's IP address
Certificateprovided by CloudflareLet's Encrypt on the VPS
RequirementCloudflare account, domain set up as a zone in Cloudflarenone or your own domain
Sign-in before the apppossible with Cloudflare Accessonly through the app itself or your own solutions
Non-web servicesonly with cloudflared or WARP on the user's devicedirectly through the open ports

Easy option: cloudflared as a One-Click App

The fastest way to get a running tunnel is through the One-Click Apps on your VPS. The app starts the official cloudflare/cloudflared image with the tunnel run command on the VPS's network. You create the tunnel in Cloudflare, enter the token, and cloudflared connects.

Requirements

  • A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. For instructions, see Set up One-Click Apps.
  • A Cloudflare account and a domain set up in Cloudflare as an active zone (with nameservers at Cloudflare). You can't use a zap.cloud subdomain.
  • At least 128 MB RAM and 1 vCPU core; 256 MB RAM is recommended. cloudflared itself usually needs only 30 to 100 MB RAM.

Create a tunnel in the Cloudflare dashboard

  1. Sign in to the Cloudflare dashboard and open Networking > Tunnels. Depending on your dashboard view, you may also find tunnels in the Zero Trust section under Networks.
  2. Click Create a tunnel, enter a name, such as vps, and confirm with Create Tunnel.
  3. Cloudflare displays installation commands for various systems. Select Docker. The command contains a long string after --token that begins with eyJ. This is your tunnel token.
  4. Copy only this string. Don't run the command itself; the One-Click App will do that for you.

You can find the token again at any time: select the tunnel, click Add a replica in the Overview tab, and copy the token from the command shown.

Warning: The token is an access key

Anyone who knows the token can connect their own servers to your tunnel and respond to requests to your domain. Don't share it and store it only in a password manager. If it falls into the wrong hands, generate a new one in the Overview tab by clicking Refresh token, then enter it in the app.

Enter the token and install

  1. Open your VPS in the ZapX dashboard and switch to the One-Click Apps tab.
  2. Search the app catalog for Cloudflared and click Install.
  3. Under App name, you can enter a custom name, such as Cloudflare Tunnel. The form doesn't ask for a subdomain because cloudflared doesn't have its own web interface.
  4. Open App configuration and enter the token in the CLOUDFLARE_TUNNEL_TOKEN field. The form marks this variable as optional, but the tunnel won't start without a token.
  5. Click Queue installation.

The installation takes about a minute because the image is small. The app card then appears in the One-Click Apps tab.

Check the connection

You can check whether the tunnel is connected in Cloudflare: after a short time, your tunnel will show as Healthy under Networking > Tunnels. In the ZapX dashboard, click Logs on the app card. When the connection is working, cloudflared logs lines containing Registered tunnel connection and the Cloudflare location it's connected to.

Warning: “Online” doesn't mean the tunnel is connected

The app only checks whether the cloudflared program is running. With an incorrect token, the card still shows Online, while cloudflared keeps trying unsuccessfully to sign in in the background and restarts about once a minute. Always check the status in Cloudflare or the Logs.

Common log messages and what they mean:

Log messageCauseSolution
"cloudflared tunnel run" requires the ID or name of the tunnel …no token entered; the card shows Degradedenter the token in App environment
Provided Tunnel token is not valid.token is incomplete or was copied incorrectlycopy the entire token again, without --token or spaces
Register tunnel error from server side error="Failed to get tunnel"the token belongs to a deleted tunnel or has been replacedenter the current token from the Cloudflare dashboard

Change or add a token

  1. Click the gear icon on the app card and switch to App environment.
  2. Open App configuration and replace the value in CLOUDFLARE_TUNNEL_TOKEN.
  3. Click Save. The app will restart with the new token.

Updates and backups

The One-Click App sets up cloudflared with a fixed image version. To check for a newer template, go to the gear icon > App update > Check for updates, then install it with Apply update. cloudflared's automatic self-update is disabled (--no-autoupdate) so the version in the container matches the app.

There's almost nothing to back up on the VPS: for a tunnel created from the dashboard, routes and settings are stored in Cloudflare, and the app only stores the token. Keep the token in your password manager. After reinstalling, enter it again and the tunnel will work as before.

Manual installation

If you don't use One-Click Apps, you can set up cloudflared yourself with Docker Compose. Create the tunnel in the Cloudflare dashboard as described above.

Requirements

  • A Linux VPS running Debian or Ubuntu with root access over SSH. For instructions on connecting, see First access over SSH.
  • Docker with the Compose plugin. The official installation script installs both: curl -fsSL https://get.docker.com | sh.
  • A Cloudflare account, a domain set up as an active zone in Cloudflare, and your tunnel token.
MinimumRecommended
CPU1 vCPU1 vCPU
RAM128 MB256 MB
Storage1 GB1 GB

cloudflared runs without any issues alongside other services on the same VPS. These values apply to cloudflared only.

Prepare the firewall

cloudflared doesn't need any inbound ports. The VPS must be able to reach Cloudflare over port 7844 (TCP and UDP) and 443 for outbound connections. With ufw's default settings, outbound traffic is allowed, so you only need to allow SSH:

bash
ufw allow OpenSSH
ufw enable
ufw status

Services you publish through the tunnel should listen only locally. If you publish a Docker container using -p 8080:80, the port is accessible from outside despite ufw because Docker sets its own firewall rules. So bind these ports to 127.0.0.1, for example, 127.0.0.1:8080:80. For more information about the firewall, see Open ports and manage the firewall on Linux.

Install with Docker Compose

Create a folder and save the token in a separate file that only root can read:

bash
mkdir -p /opt/cloudflared && cd /opt/cloudflared
echo 'TUNNEL_TOKEN=eyJ...' > .env
chmod 600 .env

Replace eyJ... with the complete token from the Cloudflare dashboard. Then create the docker-compose.yml file:

yaml
services:
  cloudflared:
    image: cloudflare/cloudflared:2026.11.0
    restart: unless-stopped
    network_mode: host
    command: tunnel --no-autoupdate run
    env_file: .env

The important lines:

  • image uses a fixed version instead of latest, so updates only happen when you install them. You can find the current version in the cloudflared releases.
  • network_mode: host runs cloudflared on the VPS's network. This lets it reach services through localhost, even if they're only bound to 127.0.0.1. Without this line, localhost refers to the cloudflared container itself.
  • command: tunnel --no-autoupdate run starts the tunnel. cloudflared reads the token from the TUNNEL_TOKEN variable in the .env file, so it doesn't appear in the process list.

Start the container:

bash
docker compose up -d

If you select your operating system (for example, Debian) instead of Docker in the Cloudflare dashboard, Cloudflare displays commands to install cloudflared as a package and set it up as a system service with cloudflared service install. Both methods produce the same result.

Check the connection

bash
docker compose logs -f

If lines containing Registered tunnel connection appear, the tunnel is connected, and its status in the Cloudflare dashboard changes to Healthy. The error messages in the table in the One-Click App section apply here too. Press Ctrl + C to stop viewing the logs; the container will keep running.

HTTPS without your own reverse proxy

Cloudflare provides the certificate for addresses that use the tunnel. You don't need nginx or Let's Encrypt on the VPS, and ports 80 and 443 can remain closed. If a web server with multiple sites is already running on the VPS, you can also point the tunnel to that web server and continue working there as usual. For instructions on setting up nginx, see Set up a reverse proxy with nginx on Linux; to create a certificate for direct access without Cloudflare, see Create an SSL certificate (Let's Encrypt).

Back up your data

Back up /opt/cloudflared/docker-compose.yml and /opt/cloudflared/.env. For a tunnel created from the dashboard, cloudflared doesn't create any other data; routes and access rules are stored in Cloudflare. The .env file contains the token, so make sure to store the backup securely.

Update cloudflared

Enter the new version in docker-compose.yml and download the image again:

bash
cd /opt/cloudflared
docker compose pull
docker compose up -d

The tunnel will be disconnected for a few seconds while it restarts. If you don't want any interruption, run a second connector with the same token on another server and update them one at a time.

Publish services through the tunnel

Once the tunnel is connected, you can decide which address leads to which service. This is all done in the Cloudflare dashboard; you don't need to change anything in the One-Click App or container.

Create a route for an address

  1. Open Networking > Tunnels, select your tunnel, and switch to the Routes tab.
  2. Click Add route and select Published application.
  3. Under Subdomain, enter the name you want, such as status, and select your domain under Domain.
  4. Under Service URL, enter the address of the service on the VPS, for example, http://localhost:3001.
  5. Click Add route.

Cloudflare automatically creates the appropriate DNS record for the subdomain. After a few seconds, the service will be available at https://status.example.com. For multi-level subdomains (for example, app.team.example.com), you need an additional certificate from Cloudflare (Advanced Certificate); a simple subdomain such as status.example.com works without one.

Which Service URL should you use?

The One-Click App and Compose file above run on the VPS's network. So localhost refers to the VPS itself:

Service on the VPSService URL
Container or program on a port, e.g. 127.0.0.1:8080http://localhost:8080
Web server (nginx, Apache) on port 80http://localhost:80
One-Click App with its own subdomainhttps://localhost:443, then under Additional application settings > TLS, set Origin Server Name, and under HTTP, set HTTP Host Header to the app's subdomain

One-Click Apps are accessible through the One-Click Apps proxy, which selects the right app based on the subdomain. That's why the route needs the app's subdomain. Note: Apps that need to know their own address (for example, to redirect after sign-in) often redirect you back to their original subdomain. For these apps, the tunnel is mainly useful as an additional access point with Cloudflare Access, not as a replacement for the app's address.

Tip: Error 502 or 1033 in the browser

If Cloudflare shows error 1033, the tunnel isn't connected: check the status and logs. With a 502 Bad Gateway, the tunnel is connected, but cloudflared can't reach the service. The logs will show Unable to reach the origin service. Check the port and protocol in the Service URL and make sure the service is running.

Add extra protection with Cloudflare Access

Admin interfaces in particular (database tools, Docker management, monitoring) shouldn't be accessible to everyone. With Cloudflare Access, Cloudflare asks users to sign in before access, and the request reaches your VPS only after that:

  1. In the Cloudflare dashboard, open Zero Trust > Access controls > Applications and click Create new application.
  2. Select Self-hosted and private and click Add public hostname.
  3. Select the subdomain and domain for your route, for example, status and example.com.
  4. Under Access policies, create a rule with the Allow action that, for example, only allows your email address. Without a matching Allow rule, Access won't let anyone through.
  5. Select One-time PIN as the sign-in method if you don't use your own identity provider. Cloudflare will then send a code to the allowed email address.
  6. Click Create.

The app itself keeps its own sign-in. Access adds another layer in front; it doesn't replace secure passwords in the app.

Limitations

  • Only web services are public: Only HTTP and HTTPS services are accessible in a browser. SSH, RDP, and other TCP services work only if the user runs cloudflared or Cloudflare's WARP client. You can't publish game servers or other UDP services for external players through a tunnel. They remain directly accessible and protected by ZAP-Hosting's DDoS protection.
  • A Cloudflare account and zone are required: The domain must use Cloudflare's nameservers.
  • Individual request size: Cloudflare limits the size of a request to 100 MB on the Free and Pro plans. Large file uploads, for example to cloud software, may fail as a result.
  • Dependence on Cloudflare: If Cloudflare or the tunnel has an outage, the published addresses won't be accessible, even if the service is running on the VPS.
  • Traffic through Cloudflare: HTTPS terminates at Cloudflare. If you have data that nobody but you should be able to decrypt, a VPN directly to the VPS is a better choice.

Conclusion

With cloudflared, you can make web services on your VPS accessible under your own domain without opening ports or managing certificates. You manage tunnels and routes in Cloudflare, and only a small service with your token runs on the VPS. The fastest way is to use a One-Click App: enter the token, check the status in Cloudflare, and create your first route. Protect admin interfaces further with Cloudflare Access, and remember that Online on the app card only means that cloudflared is running, not that the tunnel is connected.

Free tools

Related tools for servers and developers

View all

FAQ

Frequently asked questions

The One-Click App is the quickest option: enter the tunnel token from the Cloudflare dashboard, view logs directly on the app card, and install updates through the dashboard. Manual installation with Docker Compose is useful if you don't use One-Click Apps on your server, want to run cloudflared as a system service without Docker, or want to choose the version yourself. In both cases, you manage the tunnel and its routes in Cloudflare.
In the Cloudflare dashboard, go to Networking > Tunnels. When you create a tunnel, Cloudflare displays an installation command; the token is the long string after --token that begins with eyJ. For an existing tunnel, select it and click Add a replica in the Overview tab. If the old token is no longer secure, use Refresh token to generate a new one.
The app status only tells you that the cloudflared program is running. Open the logs on the app card: “Failed to get tunnel” or “Provided Tunnel token is not valid.” means the token is wrong or outdated. If your browser shows error 1033, the tunnel isn't connected. With a 502 Bad Gateway, the tunnel is connected, but the route's Service URL is wrong or the service isn't running. If you haven't created a route yet, add one in the tunnel under Routes > Add route > Published application.

Feedback

Was this article helpful?

Your feedback helps us prioritize and improve content.

0 of 0 people found this article helpful.

Personal support

Need more help than the guide provides?

Our ZAP-Hosting support team knows your product — briefly describe your issue and we'll help you personally.

Zappy knows this guide and answers you right in the chat.