Cloudflare Tunnels
You can run Coolify on your local machine (like old laptop/Raspberry PI) and expose it to the internet without opening any ports on your router with Cloudflare Tunnels.
For more details about CF Tunnels, please visit this page.
Setup Cloudflared
You have at least two ways to setup Cloudflare Tunnels with Coolify.
Automated
-
Setup Tunnels on Cloudflare
-
Go to
https://one.dash.cloudflare.com/
. -
Select your account.
-
Open
Networks
->Tunnels
->Create a Tunnel
-
Connector:
Cloudflared
-
Choose any name you like.
-
Copy your
Cloudflare Tunnel Token
from any of the commands.
- On the
Route Tunnel
tab, add the following tunnels:
-
-
Setup Tunnels on Coolify
-
Add a new server with your server’s
IP Address
- it will be reconfigured later on. -
Validate the server.
-
After the server is validated, click on
Configure
in theCloudflare Tunnels
section. -
Paste
Cloudflare Tunnel Token
from the previous step and set theSSH Domain
to the domain you set in the previous step.
-
Manual
WIP
Setup Resources in Coolify
You have several options to use Cloudflare Tunnels with Coolify.
- One domain -> One resource.
- Wildcard subdomain -> All resources.
One domain -> One resource
In this case, you need to add a public domain every time you would like to expose a new resource through Cloudflare Tunnels.
- Go to your tunnel settings on Cloudflare. (https://one.dash.cloudflare.com/ -> Networks -> Tunnels -> Select your tunnel)
- Switch to
Public Hostname
tab. - Add a new
Public Hostname
. - Go to Coolify and to your resource settings: - Remove any
Domains
settings. - SetPort Mappings
to the same port that you set in thePublic Hostname
settings. - Deploy & enjoy.
Wildcard subdomain -> All resources
In this case, you only need to setup a wildcard domain once and you can expose all your resources through it.
- Go to your tunnel settings on Cloudflare. (https://one.dash.cloudflare.com/ -> Networks -> Tunnels -> Select your tunnel)
- Switch to
Public Hostname
tab. - Add a new wildcard
Public Hostname
. - In Cloudflare go to
Networks -> Tunnels
and click on your tunnel name. From the sidebar copy theTunnel ID
. - In Cloudflare go to your
DNS
settings and add a newCNAME
record with the following settings:Name
:*
Target
:<Tunnel ID>.cfargotunnel.com
TTL
:Auto
- Go to Coolify and to your resource settings.
Set the Domains
to any subdomain of the wildcard domain you set in the previous step.
- Deploy & enjoy.
Full HTTPS/TLS Setup (Traefik/Coolify Proxy)
The above setup with the redirect from http -> https
in Cloudflare gets you most the of the way by using their tunnels.
However you’ll likely find yourself having some issues with some services where the domain name is configured as an environment variable as a http url in a service and then fails because the urls mismatch due to the automatic redirect.
This becomes particularly important with some services when you first try to set them up and configure them.
Authentication services such as Logto are affected where the JWT token issuer is different from the callback url, this makes initial setup of the service impossible, unless a alternative URL is provided to the compose somehow.
The best way to be able to solve this would be to be able to set https://
on the domains for your services, or within your wildcard domain to always be https in Coolify.
If you’ve tried this, you may have run into the issue where you get caught in a redirect loop.
To set up Coolify wildcard domains so that you can set https://
in the url for services etc. Then you’ll need to do and configure the following things:
-
Create a new origin certificate in Cloudflare for the domain you want to set it up for (
*.yourdomain.com
,yourdomain.com
). -
Add it to the origin server and configure the Traefik proxy to use the newly created certificate (see custom-ssl-certs on how to get them on your server). You can add this configuration through the UI if you like. We called it
cert.yaml
. -
Set SSL/TLS encryption mode to full (strict) in Cloudflare.
-
Configure the tunnel to use
https
and then in the tunnelAdditional application settings -> TLS
set the Origin Server Name to be the root domain you want it to be (i.e -yourdomain.com
) -
Set “Always Use HTTPS” in Cloudflare (
managing your domain -> SSL/TLS -> Edge Certificates
). -
Set a
https
domain name on any service in Coolify as a subdomain of the domain name we just setup - i.ehttps://myproject.yourdomain.com
.
If configured correctly all of your traffic to any of the subdomains will now work on https
as the FQDN in the UI and when visiting in a browser.
Post Setup
After everything is setup, you can fully disable direct access to your server by disabling all the ports (except SSH (port:22 by default)
) on your firewall.
Setup self-hosted Coolify
You can use the one domain without Coolify Proxy
or wildcard setup with Coolify Proxy
to expose your self-hosted Coolify instance to the internet.
With the wildcard
setup, you have nothing to do.
With the one domain
setup, you need a bit more setup with Coolify to make it work.
Let’s say you configured the following Public Hostnames
in Cloudflare:
app.coolify.io
mapped tolocalhost:8000
realtime.coolify.io
mapped tolocalhost:6001
terminal.coolify.io
mapped tolocalhost:6002
After you installed Coolify, you need to add 3 lines your .env
file, located in /data/coolify/source
folder.
This tells Coolify how to connect to it’s realtime server through Cloudflare Tunnels.
Restart Coolify with the installation script.
If you have a firewall, you also need to allow the following ports.
Verify
- Navigate to your Coolify instance, as in the example:
https://app.coolify.io
. - Login with the root user (the first user you created after installation).
- Open another tab/window and navigate to
https://app.coolify.io/realtime
. On the other tab (opened in point 2), you should see a notification about the test event. - If you know what are you doing, you can check the network tab as well. Search for a websocket connection.