Skip to content
Huseyin Babal
Go back

Coolify on Hetzner: git push deploys, a panel only you can reach, and offsite Postgres backups

Coolify gives you the parts of a hosted platform that matter day to day: push to GitHub and the new version goes live, a domain with HTTPS, managed databases, scheduled backups and alerts. It runs on a server you rent, so the bill is the server’s price and nothing scales behind your back.

This post is the full setup I ran on November 27, 2026, with every config file and command. The app is a small Go link shortener (Postgres for links, Redis for click counters). Everything below was built on one server and torn down afterwards.

The setup at a glance

PieceChoice
ServerHetzner CPX22, Helsinki, 2 AMD vCPU, 4 GB RAM, 80 GB disk, 20 TB traffic
OSUbuntu 24.04 LTS
PlatformCoolify v4.7.9 (Traefik v3 as its proxy)
DatabasesPostgreSQL 18 (postgres:18-alpine), Redis 8
CodeGitHub App with access to one repository
EdgeCloudflare, proxied DNS, free plan
BackupsCoolify scheduled backup to Hetzner Object Storage (S3 API)
AlertsDiscord webhook

Request path: visitor → Cloudflare → Hetzner Cloud Firewall (80/443 open to Cloudflare’s ranges only) → Traefik → app container → Postgres / Redis on Coolify’s internal Docker network.

1. Create the firewall before the server

Right after installation Coolify serves a registration page, and the installer prints that the root account must be created within 10 minutes. Whoever registers first owns the server. So the server should never be reachable on the panel port by anyone but you, not even for a minute.

Hetzner’s server form no longer creates firewalls inline, so create it first on the Firewalls page and select it in the server form:

RulePortSource
SSH22your IPv4 /32 and IPv6 /64
Coolify panel8000your IPv4 /32 and IPv6 /64
Coolify realtime6001–6002your IPv4 /32 and IPv6 /64
HTTP80any (narrowed to Cloudflare in step 8)
HTTPS443any (narrowed to Cloudflare in step 8)

Ports 6001 and 6002 are easy to miss. They carry the panel’s live updates. With only 8000 open the panel loads, but buttons like Start do nothing and show no error.

2. The server

At the time of writing the cheapest line (Cost-Optimized, CX) showed Limited availability and couldn’t be ordered, so I took a CPX22 from the Regular Performance line. In Helsinki it was €16.49/month; the same type in Nuremberg and Falkenstein was €3 more. A primary IPv4 adds €0.50.

Pick Ubuntu 24.04 (the form defaulted to 26.04), add your SSH public key so Hetzner never emails a root password, and select the firewall from step 1.

3. Install Coolify

ssh coolify
curl -fsSL https://cdn.coollabs.io/coolify/install.sh | sudo bash

The script installs Docker, pulls Coolify’s own containers (the app, its Postgres and Redis, a helper image) and finished with Installed in 1m 43s. Open http://<server-ip>:8000, register, choose This machine as the place apps run, and let the wizard create the first project.

4. Postgres and Redis

New Resource → Databases → PostgreSQL, image PostgreSQL 18. Coolify generates the user and password, pulls the image, creates a volume and starts the container. Then the same for Redis: the default offered is Valkey 9 (the open source Redis fork); I picked Redis 8.

Each database page shows an internal URL, the address on Coolify’s Docker network. The app connects through that, so neither database needs a public port. A port scan later confirms 5432 and 6379 are closed from outside.

5. Connect GitHub

Integrations → Sources → New Source → GitHub App. The app name has to be unique on GitHub, so add a few random characters. Register With GitHub sends a manifest with all permissions and URLs filled in; on GitHub you only click Create GitHub App, then install it with Only select repositories and pick the one repo.

If GitHub asks you to confirm your password first, it can drop the manifest and show “We didn’t find an App Manifest”. Confirm, go back to Coolify and click Register With GitHub again.

The webhook URL GitHub stores is http://<server-ip>:8000/... at this point. The firewall doesn’t let GitHub reach that port, so it gets replaced in step 7.

6. The app and its first deploy

The app:

package main

import (
	"context"
	"crypto/rand"
	"encoding/base64"
	"encoding/json"
	"errors"
	"log"
	"net/http"
	"os"
	"time"

	"github.com/jackc/pgx/v5"
	"github.com/jackc/pgx/v5/pgxpool"
	"github.com/redis/go-redis/v9"
)

type app struct {
	db  *pgxpool.Pool
	rdb *redis.Client
}

func main() {
	ctx := context.Background()
	db, err := pgxpool.New(ctx, os.Getenv("DATABASE_URL"))
	if err != nil {
		log.Fatal(err)
	}
	opt, err := redis.ParseURL(os.Getenv("REDIS_URL"))
	if err != nil {
		log.Fatal(err)
	}
	a := &app{db: db, rdb: redis.NewClient(opt)}
	if _, err := db.Exec(ctx, `CREATE TABLE IF NOT EXISTS links (
		code TEXT PRIMARY KEY, url TEXT NOT NULL, created_at TIMESTAMPTZ NOT NULL DEFAULT now())`); err != nil {
		log.Fatal(err)
	}

	mux := http.NewServeMux()
	mux.HandleFunc("POST /links", a.create)
	mux.HandleFunc("GET /links/{code}", a.stats)
	mux.HandleFunc("GET /{code}", a.redirect)
	mux.HandleFunc("GET /healthz", a.health)
	mux.HandleFunc("GET /{$}", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("shortener is running (v3)\n"))
	})
	port := os.Getenv("PORT")
	if port == "" {
		port = "8080"
	}
	log.Println("listening on :" + port)
	log.Fatal(http.ListenAndServe(":"+port, mux))
}

func (a *app) create(w http.ResponseWriter, r *http.Request) {
	var in struct{ URL string `json:"url"` }
	if err := json.NewDecoder(r.Body).Decode(&in); err != nil || in.URL == "" {
		http.Error(w, "want {\"url\": \"...\"}", http.StatusBadRequest)
		return
	}
	b := make([]byte, 4)
	rand.Read(b)
	code := base64.RawURLEncoding.EncodeToString(b)
	if _, err := a.db.Exec(r.Context(), `INSERT INTO links (code, url) VALUES ($1, $2)`, code, in.URL); err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	writeJSON(w, http.StatusCreated, map[string]string{"code": code, "url": in.URL})
}

func (a *app) redirect(w http.ResponseWriter, r *http.Request) {
	code := r.PathValue("code")
	url, err := a.rdb.Get(r.Context(), "url:"+code).Result()
	if err == redis.Nil {
		err = a.db.QueryRow(r.Context(), `SELECT url FROM links WHERE code = $1`, code).Scan(&url)
		if errors.Is(err, pgx.ErrNoRows) {
			http.NotFound(w, r)
			return
		}
		if err == nil {
			a.rdb.Set(r.Context(), "url:"+code, url, time.Hour)
		}
	}
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	a.rdb.Incr(r.Context(), "clicks:"+code)
	http.Redirect(w, r, url, http.StatusFound)
}

func (a *app) stats(w http.ResponseWriter, r *http.Request) {
	code := r.PathValue("code")
	var url string
	if err := a.db.QueryRow(r.Context(), `SELECT url FROM links WHERE code = $1`, code).Scan(&url); err != nil {
		http.NotFound(w, r)
		return
	}
	clicks, _ := a.rdb.Get(r.Context(), "clicks:"+code).Int()
	writeJSON(w, http.StatusOK, map[string]any{"code": code, "url": url, "clicks": clicks})
}

func (a *app) health(w http.ResponseWriter, r *http.Request) {
	if err := a.db.Ping(r.Context()); err != nil {
		http.Error(w, "postgres: "+err.Error(), http.StatusServiceUnavailable)
		return
	}
	if err := a.rdb.Ping(r.Context()).Err(); err != nil {
		http.Error(w, "redis: "+err.Error(), http.StatusServiceUnavailable)
		return
	}
	w.Write([]byte("ok\n"))
}

func writeJSON(w http.ResponseWriter, code int, v any) {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(code)
	json.NewEncoder(w).Encode(v)
}

go.mod needs github.com/jackc/pgx/v5 and github.com/redis/go-redis/v9 (v5.13.0 and v9.24.0 here, Go 1.27.1).

New Resource → Git Repository with GitHub App, pick the repo, Load Repository. Coolify finds the Dockerfile and reads the port from its EXPOSE line. Before the first deploy, add two variables under Environment Variables (Developer View takes them as .env lines):

DATABASE_URL=<Postgres internal URL from its page>
REDIS_URL=<Redis internal URL from its page>

The first deploy took 67 seconds, 61 of them the Go build on the server. Coolify also gives the app a temporary *.sslip.io address (HTTP only) to test with:

curl -s $APP/
curl -s $APP/healthz
curl -s -X POST $APP/links -d '{"url":"https://coolify.io"}'
CODE=$(curl -s -X POST $APP/links -d '{"url":"https://go.dev"}' | jq -r .code)
curl -s -o /dev/null -w '%{http_code} -> %{redirect_url}\n' $APP/$CODE

7. Health checks: a broken release never goes live

Under Healthcheck: HTTP, port 8080, path /healthz, interval 10 s, retries 3, timeout 5 s, start period 5 s. Coolify then only switches traffic to a new container after it passes, and keeps the old one serving until then.

The first Dockerfile used a distroless runtime image, and the check failed three times with stat /bin/sh: no such file. Coolify runs the check inside the container through /bin/sh, using curl or wget. Distroless has none of them. Coolify logged rolling back to the old container and the site kept answering with the previous version the whole time.

A runtime image with a shell and wget fixes it:

FROM golang:1.27 AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /shortener .

FROM alpine:3.22
COPY --from=build /shortener /shortener
EXPOSE 8080
ENTRYPOINT ["/shortener"]

With alpine the check passed on the first attempt (curl isn’t there, so it used busybox wget).

If you want to stay on distroless, the check type “Container command” doesn’t help: Coolify wraps that in /bin/sh as well.

8. Domains, a locked panel, and webhooks that still get in

DNS

On Cloudflare: an A record shortener → server IP, proxied (orange cloud), so visitors only ever see Cloudflare’s addresses. Then an A record coolify for the panel.

Cloudflare’s free Universal SSL covers example.com and *.example.com, one level deep. A name like app.cloud.example.com needs Advanced Certificate Manager ($10/month), so keep names one level deep.

In Coolify: Settings → General → Instance URL = https://coolify.example.com (Coolify rewrites its Traefik config and gets a Let’s Encrypt certificate), and on the app’s Domains page add https://shortener.example.com with port 8080. Coolify also adds a www. entry; with no DNS record behind it, it shows a DNS mismatch. Delete it, and untick the option that would also delete a DNS record.

Panel allowlist with an open webhook path

GitHub has to reach /webhooks/... on the panel for push deploys, but nothing else on the panel should be reachable by anyone but you. Traefik watches /data/coolify/proxy/dynamic/, so one extra file does it without touching Coolify’s generated config. Routers with a higher priority win over Coolify’s own:

# Coolify panel: only my IPs. GitHub webhooks: everyone.
http:
  middlewares:
    panel-allow:
      ipAllowList:
        ipStrategy:
          depth: 1          # last X-Forwarded-For entry = the visitor, added by Cloudflare
        sourceRange:
          - "<YOUR_IPV4>/32"
          - "<YOUR_IPV6>/64"
  routers:
    panel:
      rule: Host(`coolify.huseyinbabal.dev`)
      priority: 100
      entryPoints: [https]
      middlewares: [panel-allow, gzip]
      service: coolify
      tls: { certResolver: letsencrypt }
    panel-realtime:
      rule: Host(`coolify.huseyinbabal.dev`) && (PathPrefix(`/app/`) || PathPrefix(`/terminal/ws`))
      priority: 110
      entryPoints: [http, https]
      middlewares: [panel-allow]
      service: coolify-reverb
      tls: { certResolver: letsencrypt }
    panel-terminal:
      rule: Host(`coolify.huseyinbabal.dev`) && PathPrefix(`/terminal/ws`)
      priority: 120
      entryPoints: [http, https]
      middlewares: [panel-allow]
      service: coolify-terminal
      tls: { certResolver: letsencrypt }
    github-webhooks:
      rule: Host(`coolify.huseyinbabal.dev`) && PathPrefix(`/webhooks/`)
      priority: 200
      entryPoints: [https]
      service: coolify
      tls: { certResolver: letsencrypt }

The services coolify, coolify-reverb and coolify-terminal and the gzip middleware are the ones Coolify defines in its own coolify.yaml in the same folder.

scp -q panel-lock.yaml coolify:/data/coolify/proxy/dynamic/
curl -4 -s -o /dev/null -w '%{http_code}\n' https://coolify.example.com/login
ssh coolify "curl -s -o /dev/null -w '%{http_code}\n' https://coolify.example.com/login"
curl -s -o /dev/null -w '%{http_code}\n' -X POST -H 'X-GitHub-Event: ping' -d '{}' https://coolify.example.com/webhooks/source/github/events
200
403
200output

From my machine 200, from any address not in the list 403, and the webhook path answers for everyone.

Add your IPv6 /64 too. If your machine reaches the site over IPv6, the allowlist sees that address, not your IPv4, and you lock yourself out with a 403. curl -4 returning 200 while curl -6 returns 403 is the sign.

Finally, in the GitHub App settings change the webhook URL to https://coolify.example.com/webhooks/source/github/events.

Push to deploy

git commit -qam 'Bump root page to v4'
git push -q

A deployment with source Webhook shows up in Coolify within seconds. The new version answered about a minute after the push. During the rolling switch both versions answered requests for about five seconds.

9. Close the origin to everyone but Cloudflare

Cloudflare publishes its ranges at cloudflare.com/ips-v4 and cloudflare.com/ips-v6 (15 IPv4 and 7 IPv6 ranges when I checked). Put them as the only sources of the HTTP and HTTPS rules in the Hetzner firewall.

curl -s -m 5 -o /dev/null -w '%{http_code}\n' --resolve shortener.example.com:443:$ORIGIN https://shortener.example.com
curl -s -o /dev/null -w '%{http_code}\n' https://shortener.example.com
000
200output

Straight to the server: timeout. Through Cloudflare: 200. The origin still gets its own Let’s Encrypt certificate through the proxy (HTTP-01 works), which you can check with openssl s_client -connect $ORIGIN:443 -servername shortener.example.com.

Putting the panel behind Cloudflare too

Once 80/443 only accept Cloudflare, a DNS-only panel record stops working, so switch the panel record to proxied as well. Now Traefik sees Cloudflare’s address as the client and the allowlist answers 403 to you too. Tell Traefik to trust X-Forwarded-For from Cloudflare’s ranges on both entrypoints:

ssh coolify
cd /data/coolify/proxy
CF=$({ curl -s https://www.cloudflare.com/ips-v4; echo; curl -s https://www.cloudflare.com/ips-v6; } | paste -sd, -)
for ep in http https; do sed -i "/address=:443/a\      - --entrypoints.$ep.forwardedHeaders.trustedIPs=$CF" docker-compose.yml; done
grep -c trustedIPs docker-compose.yml
docker compose up -d

The ipStrategy: depth: 1 in the middleware makes the allowlist use the last X-Forwarded-For entry, which is the address Cloudflare saw. Keep a copy of docker-compose.yml before editing it.

After that: 200 from me, 403 from anywhere else, webhooks open. A scan from a separate server showed ports 22, 80, 443, 5432, 6001, 6002, 6379 and 8000 all filtered:

nmap -Pn -n --max-retries 1 -p 22,80,443,5432,6001,6002,6379,8000 $TARGET

10. Backups to Object Storage, and a restore drill

A backup on the same disk dies with the server. In Hetzner: Object Storage → Create Bucket (bucket creation in Helsinki was disabled, so it went to Nuremberg; the dialog showed at most €6.49/month with 1 TB included), then Security → S3 credentials → Generate credentials.

In Coolify, Integrations → Storage → New Storage, type S3:

FieldValue
Endpointhttps://nbg1.your-objectstorage.com
Regioneu-central
Bucketyour bucket name
Access / secret keyfrom the Hetzner dialog

On the Postgres resource: Backups → Add, frequency daily, enable S3 with that storage, save, then Back Up Now. The dump (about 2 KB here) landed in the bucket in 5 seconds, under the same path Coolify uses on disk: data/coolify/backups/databases/<team>/<db-name>/pg-dump-postgres-<timestamp>.dmp.

The drill:

docker exec -it $(docker ps -qf name=<postgres-container>) psql -U postgres
select code, url from links;
drop table links;

Short links now return 500. Restore with Import Backup → Storage → the S3 storage, paste the file path, Check File, Restore From Storage. Coolify asks you to type Confirm Deletion and your panel password.

Turn on Replace objects that already exist before restoring. Between the drop and the restore the app restarted and ran CREATE TABLE IF NOT EXISTS, so an empty links table existed again and a plain restore stopped with relation "links" already exists. With the option on, all rows came back and the redirects worked.

Click counters were gone: they live in Redis, and this backup covers Postgres only.

11. When something crashes

Notifications → Discord: paste a channel webhook URL, enable it, and pick events. Deployment failure and backup failure were on by default; I added the resource status change event. Send Test posts a test embed to the channel.

TestWhat happenedOutside
docker kill on the app containerExited (137), no restart. Docker treats a manual kill as a user stop, even with unless-stopped. Coolify showed Exited and Discord got “Resource stopped”.503 until Deploy
kill -9 on the app’s host PIDDocker restarted it within ~2 s, RestartCount 1, healthy again a few seconds later200 the whole time
docker stop on RedisHealth check failed 3 × 10 s, Traefik dropped the app after about 30 s503 for every URL
docker start on Redishealthy again within seconds302 again
APP=$(docker ps -qf name=<app-container>); kill -9 $(docker inspect -f '{{.State.Pid}}' $APP)
docker inspect -f '{{.RestartCount}} {{.State.Status}}' $APP

The Redis row is a design lesson. /healthz pings Redis, so a Redis outage took down redirects that could have been served from Postgres alone. Every dependency in the health check decides whether the app gets traffic. Put only the ones the app can’t work without in there.

What it costs

Hetzner prices (VAT excluded) on November 27, 2026:

ItemMonthly
CPX22, Helsinki€16.49
Primary IPv4€0.50
Server backups (optional)+20% of the server price
Object Storage, up to 1 TBat most €6.49
Cloudflare (free plan, one-level names)€0

Traffic: 20 TB is included with the server. Object Storage beyond 1 TB is €0.0087 per TB-hour, and egress from it €1 per TB. If the CX line is orderable in your region, the same setup fits on a CX23 (2 vCPU, 4 GB, €5.49/month in Nuremberg), which is where I ran the first test.

Checklist

Sources


Share this post:

Previous Post
Go escape analysis: reading -gcflags=-m on a small game server
Next Post
Go scheduler: how a million goroutines fit on five threads