Deploying Self Hosted Gotify Notification Server

Deploying Self Hosted Gotify Notification Server

What You’ll Need

Table of Contents

Why Gotify is the Ideal Push Notification Hub

Relying on third-party push notification services like Pushover, Telegram, or Discord for critical infrastructure alerts creates unnecessary external dependencies. When your monitoring pipeline triggers an alert because a database cluster is failing, you cannot afford to have your notification blocked by third-party rate limits or external API outages.

Gotify is an open-source, self-hosted push notification server that operates entirely under your control. It features a lightweight Go backend, an intuitive web user interface, an Android application, and a simple REST API. Notifications are delivered in real time over persistent WebSocket connections, ensuring low latency delivery without relying on proprietary cloud messaging services like Firebase Cloud Messaging.

When designing robust alerting pipelines, handling high throughput and ensuring delivery stability are crucial. If your backend applications generate hundreds of event logs per second during a system failure, you should consider Implementing Token Bucket Rate Limiting With Redis on your client apps before relaying those events to Gotify. This prevents your alert pipeline from flooding your phone with thousands of redundant messages.

Gotify allows you to segregate notification streams using separate application tokens. You can create unique tokens for backup jobs, server uptime monitors, CI/CD pipelines, and security scanners. Each application can be assigned a custom priority level ranging from 1 (low urgency background updates) to 10 (critical infrastructure outages requiring immediate attention).

Provisioning and Server Setup with Docker Compose

To deploy Gotify, start by provisioning a virtual server on Hetzner VPS. A minimal server instance with 1 vCPU and 1 GB of RAM is sufficient to handle thousands of push notifications daily while consuming under 50 MB of RAM.

First, connect to your server via SSH and prepare the host directory structure. We will create a dedicated directory for Gotify and configure a persistent volume to store SQLite database files and image assets.

Execute the following shell commands on your server:

mkdir -p /opt/gotify/data
cd /opt/gotify
chmod -R 755 /opt/gotify

Next, create the docker-compose.yml file. We will configure Gotify to run on a local bridge network and bind its web server port to localhost (127.0.0.1:8080) so that it remains hidden from the public internet until our reverse proxy is configured.

Create /opt/gotify/docker-compose.yml with this exact configuration:

version: '3.8'

services:
  gotify:
    image: gotify/server:2.5.0
    container_name: gotify
    restart: always
    ports:
      - "127.0.0.1:8080:80"
    environment:
      - GOTIFY_SERVER_PORT=80
      - GOTIFY_SERVER_KEEPCONNECTEDINTERVALLNSECS=15
      - GOTIFY_DATABASE_DIALECT=sqlite3
      - GOTIFY_DATABASE_CONNECTION=data/gotify.db
      - GOTIFY_DEFAULTUSER_NAME=admin
      - GOTIFY_DEFAULTUSER_PASS=ChangeThisSuperSecurePassword123!
      - GOTIFY_PASSSTRENGTH=10
      - TZ=UTC
    volumes:
      - /opt/gotify/data:/app/data
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:80/health"]
      interval: 30s
      timeout: 5s
      retries: 3

Start the container using Docker Compose:

docker compose up -d

Verify that the container is running properly by checking its status and health logs:

docker compose ps
docker logs gotify

💡 Fast-Track Your Project: Don’t want to configure this yourself? I build custom n8n pipelines and bots. Message me with code SYS3-HUGO.

Reverse Proxy Configuration with Caddy and SSL

Gotify requires a secure HTTPS connection for Android client synchronization and web interface management. WebSockets are heavily utilized for real-time message streaming on the /stream endpoint, requiring explicit support for HTTP connection upgrading.

We will use Caddy as our reverse proxy because it automatically manages TLS certificates via Let’s Encrypt and automatically sets standard WebSocket upgrade headers.

First, configure an A record in your DNS provider, such as Namecheap, pointing push.yourdomain.com to the public IPv4 address of your VPS.

Install Caddy on your Ubuntu server:

sudo apt-get install -y apt-transport-https curl debian-archive-keyring debian-keyring
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt-get update
sudo apt-get install caddy

Now, create the Caddy configuration file located at /etc/caddy/Caddyfile:

push.yourdomain.com {
    encode gzip zstd

    header {
        Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
        X-Content-Type-Options "nosniff"
        X-Frame-Options "DENY"
        Referrer-Policy "strict-origin-when-cross-origin"
    }

    reverse_proxy 127.0.0.1:8080 {
        header_up Host {host}
        header_up X-Real-IP {remote_host}
        header_up X-Forwarded-For {remote_host}
        header_up X-Forwarded-Proto {scheme}
    }
}

Validate and restart Caddy to issue the SSL certificate:

sudo caddy validate --config /etc/caddy/Caddyfile
sudo systemctl restart caddy

If you prefer Nginx over Caddy, create the following configuration at /etc/nginx/sites-available/gotify:

server {
    listen 80;
    server_name push.yourdomain.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name push.yourdomain.com;

    ssl_certificate /etc/letsencrypt/live/push.yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/push.yourdomain.com/privkey.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers HIGH:!aNULL:!MD5;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        proxy_connect_timeout 1m;
        proxy_send_timeout 1m;
        proxy_read_timeout 24h;
    }
}

When building automated systems that dispatch webhooks to Gotify, reliability is paramount. You should implement resilient network design principles such as Implementing Circuit Breakers for Outbound Webhook Delivery to ensure that upstream service failures do not cascade through your primary application workers.

Integrating Gotify with Webhooks and Automation Workflows

Once Gotify is running behind your reverse proxy, log into the web UI at https://push.yourdomain.com. Change your default admin password immediately under the User Settings panel.

Navigate to the APPS tab and create a new application named “Server Alerts”. Gotify will display an Application Token (e.g., A1b2C3d4E5f6G7h). Copy this token; it is required for authenticating REST API requests.

Python Integration Script

Here is a production ready Python script using requests that sends priority notifications to Gotify with Markdown formatting enabled:

import sys
import requests

GOTIFY_URL = "https://push.yourdomain.com"
APP_TOKEN = "A1b2C3d4E5f6G7h"

def send_gotify_notification(title: str, message: str, priority: int = 5) -> bool:
    endpoint = f"{GOTIFY_URL}/message?token={APP_TOKEN}"
    
    payload = {
        "title": title,
        "message": message,
        "priority": priority,
        "extras": {
            "client::display": {
                "contentType": "text/markdown"
            }
        }
    }
    
    try:
        response = requests.post(endpoint, json=payload, timeout=10)
        response.raise_for_status()
        print(f"Notification sent successfully. Status code: {response.status_code}")
        return True
    except requests.exceptions.RequestException as error:
        print(f"Failed to send Gotify notification: {error}", file=sys.stderr)
        return False

if __name__ == "__main__":
    send_gotify_notification(
        title="Server Backup Completed",
        message="**Host:** production-db-01\n**Status:** Success\n**Size:** 42.5 GB",
        priority=7
    )

Bash Shell Script Integration

You can integrate Gotify into standard Linux cron jobs and administration scripts using curl. Save the following script to /usr/local/bin/gotify-send:

#!/usr/bin/env bash

set -euo pipefail

GOTIFY_URL="https://push.yourdomain.com"
APP_TOKEN="A1b2C3d4E5f6G7h"

TITLE="${1:-System Alert}"
MESSAGE="${2:-No message content provided.}"
PRIORITY="${3:-5}"

curl --fail --silent --show-error \
  --request POST "${GOTIFY_URL}/message?token=${APP_TOKEN}" \
  --header "Content-Type: application/json" \
  --data @- <<EOF
{
  "title": "${TITLE}",
  "message": "${MESSAGE}",
  "priority": ${PRIORITY},
  "extras": {
    "client::display": {
      "contentType": "text/markdown"
    }
  }
}
EOF

Make the script executable:

chmod +x /usr/local/bin/gotify-send
/usr/local/bin/gotify-send "Disk Space Warning" "Partition `/var/log` is at 92% capacity." 8

Integration with n8n Automation Workflows

If you manage business logic or marketing pipelines using n8n Cloud, sending notifications to Gotify requires a simple HTTP Request node.

Set the following parameters in your n8n HTTP Request node:

  • Method: POST
  • URL: https://push.yourdomain.com/message
  • Authentication: None (pass via query parameters or custom headers)
  • Send Query Parameters: Enable
    • Name: token
    • Value: A1b2C3d4E5f6G7h
  • Send Body: Enable
  • Body Content Type: JSON
  • Specify Body: Using Fields Below
    • title: Workflow Execution Failed
    • message: ={{ $json.error.message }}
    • priority: 8

Securing and Maintaining Your Gotify Instance

Exposing your notification endpoint to the internet means automated scanners will attempt to brute-force your admin credentials and API endpoints.

To safeguard your deployment, set up IP ban rules by Configuring Fail2ban Security for Linux VPS. We can monitor Docker container logs or reverse proxy access logs for repeated authentication failures.

Create a Fail2ban filter for Gotify login failures at /etc/fail2ban/filter.d/gotify.conf:

[Definition]
failregex = ^<HOST> - .* "POST /login HTTP/.*" 401
ignoreregex =

Then create a jail rule in /etc/fail2ban/jail.d/gotify.local:

[gotify]
enabled = true
port = http,https
filter = gotify
logpath = /var/log/caddy/access.log
maxretry = 5
findtime = 600
bantime = 3600

Automated Database Backup Script

Because Gotify uses SQLite, backing up your configuration, application tokens, clients, and historical messages requires creating a safe copy of gotify.db.

Create a backup script at /opt/gotify/backup.sh:

#!/usr/bin/env bash

set -euo pipefail

BACKUP_DIR="/opt/gotify/backups"
TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
DB_PATH="/opt/gotify/data/gotify.db"

mkdir -p "${BACKUP_DIR}"

if [ -f "${DB_PATH}" ]; then
  sqlite3 "${DB_PATH}" ".backup '${BACKUP_DIR}/gotify_backup_${TIMESTAMP}.db'"
  gzip "${BACKUP_DIR}/gotify_backup_${TIMESTAMP}.db"
  echo "Backup created at ${BACKUP_DIR}/gotify_backup_${TIMESTAMP}.db.gz"
  
  find "${BACKUP_DIR}" -type f -name "*.db.gz" -mtime +14 -delete
else
  echo "Database file not found at ${DB_PATH}" >&2
  exit 1
fi

Make the backup script executable and schedule it daily using cron:

chmod +x /opt/gotify/backup.sh
(crontab -l 2>/dev/null; echo "0 3 * * * /opt/gotify/backup.sh > /dev/null 2>&1") | crontab -

Your self-hosted Gotify instance is now fully operational, secured behind a modern reverse proxy with automated SSL, integrated into your server scripts, and protected against automated attacks.

Getting Started

To launch your self-hosted push notification infrastructure today:

  1. Spin up a cloud server instance on Hetzner VPS or Contabo VPS.
  2. Register a domain or subdomain with Namecheap and update your A record.
  3. Deploy Gotify using Docker Compose and bind it to Caddy for automated TLS encryption.
  4. Integrate your workflow alerts directly using n8n Cloud or custom Python and Bash utilities.

Outsource Your Automation

Don’t have time? I build production n8n workflows, WhatsApp bots, and fully automated YouTube Shorts pipelines. Hire me on Fiverr, mention SYS3-HUGO for priority. Or DM at chasebot.online.

Want to automate this yourself?

Start with n8n Cloud (free tier available) or self-host on a Hetzner VPS for full control.

Want this engine running on your own VPS?

This blog publishes itself — daily, unattended, on free API tiers. The full engine, Hugo theme, and setup guide are available as System 3.

Get System 3
system online