16 Reverse Proxy with Cloudflare Tunnel
Ryan Collins edited this page 2024-01-31 16:55:51 -05:00

Description

This is the easiest reverse proxy that I have ever seen so far!

Despite a lot of reverse proxy methods in the world, unfortunately, none of them are actually easy-to-use in my opinion. As in the past, many Uptime Kuma users kept asking how to config a reverse proxy.

Recently, I just discovered that Cloudflare has added a web GUI for Cloudflare Tunnel which make it super easy to use. You can expose your Uptime Kuma to the Internet without so many configs!

For Docker users, you just need to provide a Cloudflare Tunnel token in the Settings, then you can browse Uptime Kuma on the Internet.

Read more about cloudflared: https://www.reddit.com/r/selfhosted/comments/tp0nqg/cloudflare_has_added_a_web_gui_for_controlling/

Pros:

  • Free of charge
  • Full GUI, zero-config files
  • You can put your Uptime Kuma behind firewall
  • No need to expose your real IP
  • Expose Docker port is optional
  • No need a reverse proxy software such as Nginx, Caddy or Traefik
  • Zero-config SSL
  • Free SSL

Cons:

  • (Not a con if you are already using Cloudflare) You domain's nameserver have to move to Cloudflare.
  • Added 30MB to the docker base image

Requirements

TL;DR

  1. Create a tunnel on Cloudflare Zero Trust.
  2. Get your tunnel token and set it into your Uptime Kuma instance.
  3. Map to http://localhost:3001.
  4. Profit.

Step by step

The steps are actually very simple. However, since the concept is pretty new to anyone, it may be good to write it in detail.

But trust me, once you learn, you will remember how to configure a cloudflare tunnel without this guide! (for Nginx or Traefik, I could never remember how to configure them without googling it)

  1. Go to Cloudflare Zero Trust.

  2. Network > Tunnels > Create a Tunnel

  3. Cloudflared > Next

  4. Type a Tunnel name such as uptime-kuma and save tunnel.

  5. Click the clipboard icon to copy the run command.

  6. Paste that into a text editor so you can copy the token from the end of the command.

    cloudflared.exe service install eyJhIjoiZDA4ZGNiMTUXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    `` `
    
  7. Go to your Uptime Kuma instance.

  8. Settings > Reverse Proxy

  9. Paste the token into the Cloudflare Tunnel Token field.

  10. Click Start cloudflared

  11. Go back to Cloudflare Zero Trust, if you see your connector, then click Next

  12. Choose your favorite domain name and map to http://localhost:3001

  13. Click Save and go to your domain name https://<your domain name> and profit! Yeah, it also automatically gives you SSL!

How to Stop

  • Option 1. You can remove the map on Cloudflare.
  • Option 2. You can click Stop cloudflared and Remove Token in your Uptime Kuma.

Environment Variable

Alternatively, you can set the token via a environment variable. cloudflared will be started automatically.

With this approach, you don't even need to expose your container port to the host machine.

UPTIME_KUMA_CLOUDFLARED_TOKEN=<your token>