Back to articles
Security & Anti-DDoS

Comprehensive Guide to Deploying OpenWebUI Connecting to Ollama API Secured via Cloudflare Tunnels

A detailed guide to deploying OpenWebUI connected to Ollama API on a VPS, securing access via Cloudflare Tunnels to hide the origin IP and defend against DDoS attacks.

DPTCloud Engineering4 min read
Comprehensive Guide to Deploying OpenWebUI Connecting to Ollama API Secured via Cloudflare Tunnels

OpenWebUI is an open-source web interface for self-hosted AI models, enabling connectivity to Ollama API to access various language models such as Llama, Mistral, and others. This guide provides a comprehensive walkthrough of deploying OpenWebUI connected to Ollama API on a VPS, using Cloudflare Tunnels to hide the origin IP, protect against DDoS attacks, and enhance overall network security.

Cloudflare Tunnels (formerly Cloudflare Tunnel) allows secure connections from an internal server to Cloudflare without opening network ports or exposing a public IP address. This solution is ideal for self-hosted AI models requiring remote access while safeguarding the underlying network infrastructure.

Prerequisites

  • Cloudflare account (free or paid)
  • A VPS server (minimum 4GB RAM, 2 vCPU)
  • Public IP address of the VPS (optional if using Cloudflare Tunnels)
  • A domain name (your own or a Cloudflare domain)
  • Ollama API installed on the VPS
  • Docker and Docker Compose installed

Deploying OpenWebUI and Connecting to Ollama API

We will deploy OpenWebUI using Docker Compose and configure it to connect to the Ollama API running on the same VPS or a remote server.

1. Install Ollama API

On the VPS, install Ollama using the following command:

curl -fsSL https://ollama.com/install.sh | sh

Start the Ollama service:

sudo systemctl enable ollama\nsudo systemctl start ollama

Verify Ollama is running:

ollama list

2. Install OpenWebUI

Create a new directory for OpenWebUI:

mkdir -p ~/openwebui && cd ~/openwebui

Create a docker-compose.yml file:

version: '3.8'\nservices:\n  openwebui:\n    image: openwebui/openwebui:latest\n    container_name: openwebui\n    ports:\n      - \"8080:8080\"\n    environment:\n      - OLLAMA_BASE_URL=http://ollama:11434\n    volumes:\n      - ./data:/app/data\n    restart: unless-stopped\n  ollama:\n    image: ollama/ollama:latest\n    container_name: ollama\n    ports:\n      - \"11434:11434\"\n    volumes:\n      - ollama_data:/root/.ollama\n    restart: unless-stopped\nvolumes:\n  ollama_data:

Start OpenWebUI:

docker-compose up -d

Connecting OpenWebUI with Cloudflare Tunnels

To secure access, we will use Cloudflare Tunnels instead of opening port 8080 directly.

1. Install Cloudflare Tunnel

Download and install cloudflared:

sudo apt update\nsudo apt install -y cloudflared

Log in to Cloudflare:

cloudflared tunnel login

Create a new tunnel:

cloudflared tunnel create openwebui-tunnel

Create a configuration file config.yml:

hostname: openwebui.yourdomain.com\nurl: http://localhost:8080\ncredentials-file: /root/.cloudflared/openwebui-tunnel.json

Run the tunnel:

cloudflared tunnel run openwebui-tunnel

2. Configure DNS

In Cloudflare, create a DNS record for openwebui.yourdomain.com pointing to the newly created tunnel.

Cloudflare will automatically issue a free SSL certificate (On-Demand TLS).

Verification and Testing

After deployment, access https://openwebui.yourdomain.com to verify OpenWebUI is operational.

In the interface, go to Settings → API → Connect to Ollama and enter http://ollama:11434.

Test the Ollama connection with the following command:

curl -X GET http://localhost:11434/api/tags

Ensure the response returns a list of Ollama models.

Troubleshooting

  • Cannot access OpenWebUI: Check if the Cloudflare Tunnel is running correctly using cloudflared tunnel list.
  • Cannot connect to Ollama: Verify Docker networking and ensure the OpenWebUI container can reach the Ollama container via the name ollama.
  • SSL certificate not working: Ensure DNS is correctly pointed and Cloudflare has issued the certificate.

References

Related infrastructure & engineering guides: Cloud VPS with L3/L4/L7 Anycast Anti-DDoS · Optimizing Caddy Server: Solution for Handling Over 20,000 Customer Domains with On-Demand TLS

DPTCloud Tier III Infrastructure

High-RAM Cloud VPS Plans Optimized for AI, Databases & Cache

Enterprise RAID 10 NVMe SSDs, CMC & FPT District 9 uplinks with Anycast Anti-DDoS and 99.99% SLA.

View 22 VPS Plans
ECO · vn-02Recommended

VPS-4E

297.000 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe
ECO · vn-02

VPS-5E

614.900 ₫ / mo

10% VAT included

  • CPU: 8 vCPU
  • RAM: 16 GB
  • SSD: 100 GB NVMe
ADVANCED · vn-03Recommended

VPS-4T

548.900 ₫ / mo

10% VAT included

  • CPU: 4 vCPU
  • RAM: 8 GB
  • SSD: 50 GB NVMe

Related Articles

View all
ZaloZalo SupportDiscord0384 753 478