October 30, 2023 7 minutes minutes read Admin

Uptime Kuma Installation on Ubuntu 22.04 using Docker

Uptime Kuma is a self-hosted monitoring tool that is easy to use and offers a range of features including monitoring uptime for various services, notifications, multi-language support, multiple status pages, and more. This tutorial will guide you through the process of installing Uptime Kuma on Ubuntu 22.04 using Docker.

Prerequisites

Before you start with the installation process, make sure you have root or sudo access to your Ubuntu server.

Step 1: Update the System and Install Required Software

First, update the system and install necessary software like git and Nginx. Reboot the server once done.

sudo apt update
sudo apt upgrade
sudo reboot
sudo apt install nginx git

Step 2: Install Docker

Before installing Docker Engine for the first time on a new host machine, you need to set up the Docker repository. Afterward, you can install and update Docker from the repository.

Set Up The Repository

Update the apt package index and install packages to allow apt to use a repository over HTTPS:

sudo apt-get update
sudo apt-get install ca-certificates curl gnupg

Add Docker’s official GPG key:

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

Use the following command to set up the repository:

echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker Engine

Update the apt package index:

sudo apt-get update

To install the latest version, run:

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Step 3: Create Docker Volume Directory

Create a directory to store your Docker volume:

mkdir -p /docker-volume
mkdir -p /docker-volume/uptime-kuma
mkdir -p /opt/uptime-kuma

Navigate to the uptime-kuma directory and create a docker-compose file:

cd /opt/uptime-kuma

Create a docker-compose.yml file with the following details. This configuration will use port 8001 for outside access and will restart the service automatically in case of server shutdown or crash. The volume will be added to the directory created earlier (/docker-volume/uptime-kuma).

---
# Simple docker-compose.yml
# You can change your port or volume location

version: '3.3'

services:
  uptime-kuma:
    image: louislam/uptime-kuma:1
    container_name: uptime-kuma
    volumes:
      - ./uptime-kuma-data:/app/data
    ports:
      - 3001:3001  # <Host Port>:<Container Port>
    restart: always

Run Docker compose to create the container:

docker-compose up -d

Step 4: Configure Nginx

Allow public traffic to ports 80 and 443 (HTTP and HTTPS) using the “Nginx Full” UFW application profile:

sudo ufw allow 80
sudo ufw allow 443

Add the uptime_kuma configuration into the Nginx proxy by replacing example.com with your domain in the /etc/nginx/sites-available/uptime-kuma.conf file:

sudo vi /etc/nginx/sites-available/uptime-kuma.conf

Add the following configuration to the file:

server  {
    listen 80;
    server_name    example.com;
    location / {
        proxy_pass         http://localhost:8001;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection "upgrade";
        proxy_set_header   Host $host;
    }
}

Create a symbolic link to sites-enabled and activate the site. Then, check that the configuration is correct and reload Nginx to apply the settings:

sudo ln -s /etc/nginx/sites-available/uptime-kuma.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Step 5: Install Certbot

CertBot will help us generate a certificate for our domain and automatically make Nginx use the certificate and port 443.

sudo apt install certbot python3-certbot-nginx

Generate a Let’s Encrypt certificate and alter the Nginx configuration in the file uptime-kuma.conf:

sudo certbot --nginx -d your_domain_here

Step 6: Exposing Status Page Only

If you would like to make your page public but don't want users to access your admin dashboard, you may use the following configuration, replacing public-status.example.com and page-name with your domain and page name respectively:

server  {
    server_name    public-status.example.com;

    location = /status/page-name {
        proxy_pass         http://localhost:8001;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection "upgrade";
        proxy_set_header   Host $host;
    }

    location /api {
        proxy_pass         http://localhost:8001;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection "upgrade";
        proxy_set_header   Host $host;
    }

    location /assets {
        proxy_pass         http://localhost:8001;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection "upgrade";
        proxy_set_header   Host $host;
    }

    location ~* \.(svg|ico)$ {
        proxy_pass         http://localhost:8001;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection "upgrade";
        proxy_set_header   Host $host;
    }

    location / {
        return 301 https://$host/status/page-name;
    }

    listen 443 ssl; 
    ssl_certificate /etc/letsencrypt/live/public-status.example.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/public-status.example.com/privkey.pem; 
    include /etc/letsencrypt/options-ssl-nginx.conf; 
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; 
}

server  {
    if ($host = public-status.example.com) {
        return 301 https://$host$request_uri;
    } 

    listen 80;
    server_name    public-status.example.com;
    return 404; 
}

At this point, you should have a fully HTTPS-enabled Uptime Kuma instance running on your server.