Aller au contenu

Déployer Open WebUI sur Ubuntu 22.04 (prêt pour la production)

Monter un frontend de chat Open WebUI durci sur Ubuntu 22.04 via Docker, pointé sur votre endpoint Ollama ou vLLM, avec nginx, TLS Let's Encrypt et SSO OIDC.

Vous avez déjà le serveur de modèle qui roule — Ollama ou vLLM, compatible OpenAI, derrière nginx avec une clé d’API. L’équipe veut une interface de chat devant parce que personne n’a envie de faire curl sur chaque prompt. Vous démarrez Open WebUI avec docker run, le premier utilisateur entre, vous remettez ça à l’équipe. Six mois plus tard, le conteneur est exposé sur 0.0.0.0:8080 parce que la commande run avait -p 8080:8080, n’importe qui qui a l’URL peut s’inscrire parce que les inscriptions n’ont jamais été désactivées, et la base SQLite est encore sur la couche conteneur parce que personne n’a monté de volume — un docker rm plus loin et tout l’historique des conversations est parti.

Ce qui se passe

Un déploiement Open WebUI réellement prêt pour la production demande beaucoup plus que docker run. Le conteneur doit binder sur 127.0.0.1:8080 et s’asseoir derrière nginx qui termine TLS — l’inscription doit être désactivée ou restreinte au domaine SSO, OIDC doit être branché sur l’IdP de l’entreprise (Authentik, Keycloak, Google Workspace, Microsoft Entra) pour que le RBAC et le départ d’employés passent par une seule source de vérité, et le volume de données persistant doit vivre sur /var/lib/open-webui sur le disque de données. Le pointeur d’endpoint compatible OpenAI doit correspondre à l’URL Ollama ou vLLM amont, la clé d’API doit passer par une variable d’environnement (pas commitée dans le fichier compose en clair), et les montées WebSocket doivent traverser nginx parce que sinon les réponses en streaming brisent. Sautez un de ces points et l’interface de chat ou bien fuite des données vers l’internet public, ou bien dérive en dehors de la gouvernance SSO, ou bien perd silencieusement l’historique au prochain recreate du conteneur.

Comment vérifier

Après installation, les écouteurs doivent être exactement ceux-ci :

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)

Le conteneur Open WebUI doit être 127.0.0.1:8080, jamais 0.0.0.0. Le streaming chat doit faire l’aller-retour — ouvrez l’interface web, connectez-vous via OIDC, envoyez un prompt, la réponse doit s’afficher token par token. Présence WebSocket sur le fil :

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

Si nginx retourne 101 Switching Protocols (ou un 400 venant de l’amont quand le handshake WS est malformé à la main), le chemin d’upgrade est branché. Si vous obtenez 426 Upgrade Required ou un simple 200, le streaming va sembler figer à chaque requête et l’expérience est inutilisable même si l’API répond correctement.

Le correctif

Enregistrez le script ci-dessous sous /root/setup-open-webui-ubuntu22.sh, puis exécutez-le. Il déroule l’installation complète sur une VM Ubuntu 22.04 fraîche : mise à jour de base, ajustement noyau, limites de fichiers, UFW, durcissement SSH, unattended-upgrades, Docker CE + plugin compose, Open WebUI en service compose unique bindé sur 127.0.0.1:8080 avec /var/lib/open-webui monté, variables d’environnement pour OIDC + l’endpoint compatible OpenAI amont + l’inscription désactivée, nginx qui termine TLS avec entêtes proxy WebSocket-aware, et Let’s Encrypt via certbot. Le fichier compose tire l’endpoint LLM amont et la clé d’API du fichier env pour que le secret ne vive jamais dans un YAML commité en 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."

Rendez-le exécutable et lancez-le :

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=<clé amont> \
  OIDC_CLIENT_ID=open-webui \
  OIDC_CLIENT_SECRET=<depuis votre IdP> \
  OIDC_PROVIDER_URL=https://sso.example.com/application/o/openwebui/ \
  /root/setup-open-webui-ubuntu22.sh

Le premier utilisateur qui se connecte via OIDC devient admin — il n’y a pas de mot de passe de bootstrap séparé. Enregistrez https://chat.example.com/oauth/oidc/callback comme URI de redirection dans votre IdP, laissez ENABLE_SIGNUP=false dans /opt/open-webui/.env (déjà fait par le script) pour que les inscriptions par mot de passe restent désactivées, et traitez le répertoire /var/lib/open-webui comme frontière de persistance — une tâche restic à la pgbackrest qui couvre ce chemin suffit puisque l’historique des conversations est en SQLite à cet endroit.

Faites tourner l’Open WebUI de production dans un environnement infogéré par Stack Harbor avec cadence de mise à jour, monitoring et escalade Sev-1 en place : Environnements infogérés. Pour la couche d’inférence derrière, voir les guides Ollama et vLLM — et Monitoring & Support si vous voulez l’utilisation GPU et le débit en tokens branchés sur le même tableau de bord.