Skip to content

Deploying Open WebUI on Ubuntu 22.04 (production-ready)

Stand up a hardened Open WebUI chat frontend on Ubuntu 22.04 via Docker, pointed at your Ollama or vLLM endpoint, with nginx, Let's Encrypt TLS and OIDC SSO.

You’ve already got the model server running — Ollama or vLLM, OpenAI-compatible, behind nginx with an API key. The team wants a chat UI in front of it because nobody wants to curl every prompt. You spin up Open WebUI with docker run, the first user logs in, you hand it over. Six months later the container is exposed on 0.0.0.0:8080 because the run command had -p 8080:8080, anyone with the URL can self-register because signups were never disabled, and the SQLite database is still on the container layer because nobody mounted a volume — one docker rm away from losing every conversation history.

What’s happening

An Open WebUI deployment that is actually production-ready needs more than docker run. The container has to bind on 127.0.0.1:8080 and sit behind nginx terminating TLS — signup has to be disabled or restricted to the SSO domain, OIDC has to be wired to the company IdP (Authentik, Keycloak, Google Workspace, Microsoft Entra) so RBAC and offboarding flow through one source of truth, and the persistent data volume has to live on /var/lib/open-webui on the data disk. The OpenAI-compatible endpoint pointer must match the upstream Ollama or vLLM URL, the API key has to be passed via env var (not committed to the compose file in plain text), and WebSocket upgrades have to pass through nginx because streaming responses break otherwise. Skip any of these and the chat UI either leaks data to the public internet, drifts out of SSO governance, or quietly loses history on the next container recreate.

How to verify

After install, the listeners should be exactly these:

ss -lntp | grep -E ':(80|443|8080)\b'
# 0.0.0.0:80      nginx
# 0.0.0.0:443     nginx
# 127.0.0.1:8080  open-webui (docker)

The Open WebUI container must be 127.0.0.1:8080, never 0.0.0.0. Streaming chat must round-trip — open the web UI, log in via OIDC, send a prompt, the response should stream token-by-token. WebSocket presence on the wire:

curl -fsS -I -H "Upgrade: websocket" -H "Connection: upgrade" \
  https://chat.example.com/ws/socket.io/

If nginx returns 101 Switching Protocols (or a 400 from the upstream when the WS handshake is malformed by hand), the upgrade path is wired. If you get 426 Upgrade Required or a plain 200, streaming will appear to hang on every request and the UX is useless even though the API answers correctly.

The fix

Save the script below as /root/setup-open-webui-ubuntu22.sh, then run it. It runs the installer flow on a fresh Ubuntu 22.04 VM: base update, kernel tuning, file limits, UFW, SSH hardening, unattended-upgrades, Docker CE + compose plugin, Open WebUI as a single compose service bound on 127.0.0.1:8080 with /var/lib/open-webui mounted, env vars for OIDC + the upstream OpenAI-compatible endpoint + signup disabled, nginx terminating TLS with WebSocket-aware proxy headers, and Let’s Encrypt via certbot. The compose file pulls the upstream LLM endpoint and API key from the env file so the secret never lives in a YAML committed to git.

#!/usr/bin/env bash
set -euo pipefail

### Ubuntu 22.04 Open WebUI clean VM installer
### Front-end only; assumes Ollama or vLLM is reachable at OPENWEBUI_LLM_BASE_URL
### Binds Open WebUI on 127.0.0.1 only; nginx terminates TLS
### OIDC SSO is the supported login path; password signup is disabled
### No local backups; assumes VM-level backup. Conversations persist in /var/lib/open-webui (sqlite).
### Reboot remains manual

if [[ "$(id -u)" -ne 0 ]]; then
  echo "Run as root."
  exit 1
fi

: "${OPENWEBUI_DOMAIN:?Set OPENWEBUI_DOMAIN=chat.example.com}"
: "${OPENWEBUI_EMAIL:?Set OPENWEBUI_EMAIL=ops@example.com for Let's Encrypt}"
: "${OPENWEBUI_LLM_BASE_URL:?Set OPENWEBUI_LLM_BASE_URL=https://llm.example.com/v1}"
: "${OPENWEBUI_LLM_API_KEY:?Set OPENWEBUI_LLM_API_KEY=<upstream API key>}"
: "${OIDC_CLIENT_ID:?Set OIDC_CLIENT_ID}"
: "${OIDC_CLIENT_SECRET:?Set OIDC_CLIENT_SECRET}"
: "${OIDC_PROVIDER_URL:?Set OIDC_PROVIDER_URL=https://sso.example.com/application/o/openwebui/}"
OPENWEBUI_SECRET_KEY="${OPENWEBUI_SECRET_KEY:-$(openssl rand -hex 32)}"
OPENWEBUI_VERSION="${OPENWEBUI_VERSION:-main}"

echo
echo "========================================"
echo "Open WebUI Ubuntu 22.04 Setup"
echo "========================================"
echo

echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade

echo "==> Installing base packages"
apt-get -y install \
  vim curl wget ca-certificates gnupg2 \
  chrony fail2ban unattended-upgrades \
  ufw lsof tcpdump dnsutils tar gzip \
  iproute2 net-tools openssl jq pciutils \
  software-properties-common

echo "==> Enabling time sync"
systemctl enable --now chrony
timedatectl set-ntp true

echo "==> Detecting NVIDIA GPU (UI host typically has none; this is fine)"
HAS_GPU=0
if lspci | grep -qi 'nvidia'; then
  HAS_GPU=1
  echo "NVIDIA GPU detected on UI host. Not required for Open WebUI; only useful if you co-host inference."
else
  echo "No NVIDIA GPU detected on UI host. This is expected; inference runs on the upstream LLM server."
fi

echo "==> Applying kernel/network tuning"
cat > /etc/sysctl.d/99-openwebui.conf <<'SYSCTL'
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr

net.core.somaxconn = 4096
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.ip_local_port_range = 10240 65535

net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0

kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
SYSCTL

modprobe tcp_bbr || true
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system

echo "==> Setting file limits"
cat > /etc/security/limits.d/99-openwebui.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
root soft nofile 64000
root hard nofile 64000
LIMITS

echo "==> Configuring UFW"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable

echo "==> Hardening SSH while keeping root SSH key login enabled"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)

set_sshd_option() {
  local key="$1"
  local value="$2"
  if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
    sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
  else
    echo "${key} ${value}" >> /etc/ssh/sshd_config
  fi
}

set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option KbdInteractiveAuthentication no
set_sshd_option ChallengeResponseAuthentication no
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4

sshd -t
systemctl restart ssh

echo "==> Configuring fail2ban"
mkdir -p /etc/fail2ban/jail.d
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN

systemctl enable --now fail2ban

echo "==> Configuring unattended-upgrades"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUPG'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUPG

echo "==> Installing Docker CE"
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
  | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable" \
  > /etc/apt/sources.list.d/docker.list
apt-get update
apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

systemctl enable --now docker

echo "==> Preparing /opt/open-webui and /var/lib/open-webui"
mkdir -p /opt/open-webui /var/lib/open-webui
chown -R 1000:1000 /var/lib/open-webui
chmod 750 /var/lib/open-webui

cat > /opt/open-webui/.env <<ENV
OPENWEBUI_VERSION=${OPENWEBUI_VERSION}
WEBUI_SECRET_KEY=${OPENWEBUI_SECRET_KEY}

# Upstream OpenAI-compatible inference (Ollama, vLLM, or any other server)
OPENAI_API_BASE_URL=${OPENWEBUI_LLM_BASE_URL}
OPENAI_API_KEY=${OPENWEBUI_LLM_API_KEY}

# Disable native signup; OIDC is the only login path
ENABLE_SIGNUP=false
DEFAULT_USER_ROLE=user

# OIDC SSO
ENABLE_OAUTH_SIGNUP=true
OAUTH_MERGE_ACCOUNTS_BY_EMAIL=true
OAUTH_CLIENT_ID=${OIDC_CLIENT_ID}
OAUTH_CLIENT_SECRET=${OIDC_CLIENT_SECRET}
OPENID_PROVIDER_URL=${OIDC_PROVIDER_URL}.well-known/openid-configuration
OAUTH_PROVIDER_NAME=SSO
OAUTH_SCOPES=openid email profile
ENV

chmod 600 /opt/open-webui/.env

cat > /opt/open-webui/docker-compose.yml <<'COMPOSE'
services:
  open-webui:
    image: ghcr.io/open-webui/open-webui:${OPENWEBUI_VERSION}
    restart: unless-stopped
    ports:
      - "127.0.0.1:8080:8080"
    volumes:
      - /var/lib/open-webui:/app/backend/data
    environment:
      WEBUI_SECRET_KEY: ${WEBUI_SECRET_KEY}
      OPENAI_API_BASE_URL: ${OPENAI_API_BASE_URL}
      OPENAI_API_KEY: ${OPENAI_API_KEY}
      ENABLE_SIGNUP: ${ENABLE_SIGNUP}
      DEFAULT_USER_ROLE: ${DEFAULT_USER_ROLE}
      ENABLE_OAUTH_SIGNUP: ${ENABLE_OAUTH_SIGNUP}
      OAUTH_MERGE_ACCOUNTS_BY_EMAIL: ${OAUTH_MERGE_ACCOUNTS_BY_EMAIL}
      OAUTH_CLIENT_ID: ${OAUTH_CLIENT_ID}
      OAUTH_CLIENT_SECRET: ${OAUTH_CLIENT_SECRET}
      OPENID_PROVIDER_URL: ${OPENID_PROVIDER_URL}
      OAUTH_PROVIDER_NAME: ${OAUTH_PROVIDER_NAME}
      OAUTH_SCOPES: ${OAUTH_SCOPES}
      WEBUI_AUTH: True
    healthcheck:
      test: ["CMD", "curl", "-fsS", "http://127.0.0.1:8080/health"]
      interval: 30s
      timeout: 5s
      retries: 5
      start_period: 60s
COMPOSE

echo "==> Starting Open WebUI"
docker compose --env-file /opt/open-webui/.env -f /opt/open-webui/docker-compose.yml up -d

echo "==> Waiting for Open WebUI on 127.0.0.1:8080"
for i in {1..90}; do
  if ss -lntp | grep -q '127.0.0.1:8080'; then
    break
  fi
  sleep 2
done

if ! ss -lntp | grep -q '127.0.0.1:8080'; then
  echo "Open WebUI failed to listen on 127.0.0.1:8080"
  docker compose -f /opt/open-webui/docker-compose.yml logs --tail=200 || true
  exit 1
fi

echo "==> Installing nginx and certbot"
apt-get -y install nginx certbot python3-certbot-nginx

cat > /etc/nginx/sites-available/open-webui <<NGINX
upstream openwebui_backend {
    server 127.0.0.1:8080;
    keepalive 32;
}

server {
    listen 80;
    listen [::]:80;
    server_name ${OPENWEBUI_DOMAIN};
    return 301 https://\$host\$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name ${OPENWEBUI_DOMAIN};

    client_max_body_size 100M;
    proxy_read_timeout   600s;
    proxy_send_timeout   600s;
    proxy_connect_timeout 60s;
    proxy_buffering      off;

    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Content-Type-Options nosniff always;
    add_header X-Frame-Options SAMEORIGIN always;
    add_header Referrer-Policy strict-origin-when-cross-origin always;

    location /ws/ {
        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_http_version 1.1;
        proxy_pass http://openwebui_backend;
    }

    location / {
        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_http_version 1.1;
        proxy_pass http://openwebui_backend;
    }
}
NGINX

ln -sf /etc/nginx/sites-available/open-webui /etc/nginx/sites-enabled/open-webui
rm -f /etc/nginx/sites-enabled/default

nginx -t
systemctl enable --now nginx
systemctl reload nginx

echo "==> Requesting Let's Encrypt certificate"
certbot --nginx --non-interactive --agree-tos \
  -m "${OPENWEBUI_EMAIL}" -d "${OPENWEBUI_DOMAIN}" --redirect

systemctl enable --now certbot.timer

echo "==> Waiting for HTTPS listener"
for i in {1..30}; do
  if ss -lntp | grep -q ':443'; then
    break
  fi
  sleep 1
done

echo "==> Final package update"
apt-get -y upgrade

echo
echo "========================================"
echo "DONE"
echo "========================================"
echo

echo "Listeners:"
ss -lntp | grep -E ':(80|443|8080)\b' || true

echo
echo "Containers:"
docker compose -f /opt/open-webui/docker-compose.yml ps

echo
echo "Services:"
systemctl is-active docker nginx fail2ban chrony || true

echo
echo "Upstream LLM endpoint:"
echo "${OPENWEBUI_LLM_BASE_URL}"

echo
echo "Web UI:"
echo "https://${OPENWEBUI_DOMAIN}/"

echo
echo "OIDC redirect URI to register with your IdP:"
echo "https://${OPENWEBUI_DOMAIN}/oauth/oidc/callback"

echo
echo "Secrets written to /opt/open-webui/.env (mode 600). Move them to your secrets manager before going live."

echo
echo "Final step:"
echo "Open the URL, sign in via OIDC, the first SSO user becomes admin. Confirm streaming works on a real prompt; if tokens do not arrive incrementally, nginx WebSocket upgrade is misconfigured."

Make it executable and run it:

chmod 700 /root/setup-open-webui-ubuntu22.sh
OPENWEBUI_DOMAIN=chat.example.com OPENWEBUI_EMAIL=ops@example.com \
  OPENWEBUI_LLM_BASE_URL=https://llm.example.com/v1 \
  OPENWEBUI_LLM_API_KEY=<upstream key> \
  OIDC_CLIENT_ID=open-webui \
  OIDC_CLIENT_SECRET=<from your IdP> \
  OIDC_PROVIDER_URL=https://sso.example.com/application/o/openwebui/ \
  /root/setup-open-webui-ubuntu22.sh

The first user who signs in via OIDC becomes admin — there’s no separate bootstrap password. Register https://chat.example.com/oauth/oidc/callback as the redirect URI in your IdP, set ENABLE_SIGNUP=false in /opt/open-webui/.env (already done by the script) so password signups stay off, and treat the /var/lib/open-webui directory as the persistence boundary — a pgbackrest-style restic job covering that path is enough since the conversation history is in SQLite there.

Run the production Open WebUI on a Stack Harbor-managed environment with patch cadence, monitoring, and Sev-1 escalation built in: Managed Cloud Ops. For the inference tier behind it, see the Ollama and vLLM guides — and Monitoring & Support if you want GPU utilization and token-throughput alerting wired into the same dashboard.