Back to tutorials
Tutorial

Open WebUI With OAuth2 Proxy On A VPS

Protect Open WebUI with OAuth using OAuth2 Proxy, Nginx, and Docker Compose on a VPS—Google/GitHub login with secure headers.

By Anurag Singh
Updated on Nov 20, 2026
Category: Tutorial
Share article
Open WebUI With OAuth2 Proxy On A VPS

Open WebUI is easy to publish on a VPS—and that’s the problem. The default “app password” approach rarely holds up once more than a couple people use it.

In this tutorial you’ll protect Open WebUI with OAuth by putting OAuth2 Proxy in front of the UI.

Nginx will enforce access. Only the Google or GitHub identities you approve can reach the chat page.

This is a practical, single-server setup: one VPS, Docker Compose, a real domain, and TLS.

It works the same whether you run CPU-only Ollama today or move to GPU-backed inference later.

You get tighter access control, clearer logs, and an upgrade path that doesn’t require rebuilding your stack.

What you’ll build (and what you won’t)

Users will visit https://chat.example.com, complete a Google or GitHub login, and only then land in Open WebUI.

OAuth2 Proxy runs the OAuth flow, sets a secure session cookie, and passes identity headers through Nginx to the upstream.

  • You will build: Open WebUI + Ollama + OAuth2 Proxy + Nginx (TLS) on one VPS using Docker Compose.
  • You will not build: a multi-node HA auth tier, a full SSO platform, or a Kubernetes deployment.

If you need private access without opening ports, you can combine this with your existing tunnel approach.

HostMyCode has a practical guide on Cloudflare Tunnel on a VPS for private admin. The steps below assume standard HTTPS exposure.

Prerequisites and sizing for a VPS

The auth layer is lightweight. Your real sizing pressure comes from models, concurrency, and disk growth.

  • OS: Ubuntu 24.04 LTS (recommended) or Debian 12
  • VPS baseline (auth + UI only): 2 vCPU / 4 GB RAM
  • Practical baseline for CPU Ollama with a small model: 4 vCPU / 8–16 GB RAM
  • Disk: 60+ GB SSD/NVMe (models add up fast)
  • Domain: chat.example.com pointed to your VPS

For team usage, the “nice to have” becomes “required” quickly.

You need predictable CPU time, enough RAM for inference, and a disk that won’t fill up overnight.

A HostMyCode VPS matches this pattern well: one server, simple firewall rules, and you control the edge.

Software you’ll need installed:

  • Docker Engine + Docker Compose plugin
  • Nginx on the host (recommended for easier TLS and log management)
  • Certbot (Let’s Encrypt) or equivalent

Step 1: Point DNS and open the right ports

Create an A record for your subdomain:

  • chat.example.com → your VPS public IPv4

On the VPS firewall, only open what you need for HTTPS and basic management:

  • TCP 22 (SSH)
  • TCP 80 (HTTP) for ACME challenge
  • TCP 443 (HTTPS)

With UFW:

sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status

If you want a safer baseline before you expose the hostname publicly, HostMyCode’s Nginx protections map cleanly to this setup.

See Set up Fail2ban for Nginx on Ubuntu VPS.

Step 2: Install Docker (and verify it properly)

On Ubuntu, install Docker from the official repo (not the snap).

If Docker is already present, still confirm the Compose plugin is installed and working.

sudo apt update
sudo apt install -y ca-certificates curl gnupg
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

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

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

Confirm:

docker --version
docker compose version

Optional (but convenient):

sudo usermod -aG docker $USER
newgrp docker

Step 3: Create OAuth credentials (Google or GitHub)

OAuth2 Proxy needs a client ID and client secret from your provider.

Pick one provider first. You can swap later, or add another provider after the basics work.

Option A: Google OAuth (Workspace-friendly)

  • Create an OAuth consent screen (internal for Workspace teams, external otherwise).
  • Create OAuth client credentials of type “Web application”.
  • Authorized redirect URI: https://chat.example.com/oauth2/callback

Option B: GitHub OAuth (simple for dev teams)

  • Create a GitHub OAuth App.
  • Authorization callback URL: https://chat.example.com/oauth2/callback

Important: Your redirect URI must match exactly.

The wrong scheme, a different hostname, or a missing path is the most common cause of redirect_uri_mismatch.

Step 4: Create a secure cookie secret

OAuth2 Proxy signs/encrypts its session cookie with a secret.

Generate a strong value on the VPS:

python3 -c "import os,base64; print(base64.urlsafe_b64encode(os.urandom(32)).decode())"

Save it somewhere safe. You’ll paste it into the config file next.

Step 5: Write Docker Compose for Open WebUI + Ollama + OAuth2 Proxy

Create a project directory:

sudo mkdir -p /opt/openwebui-oauth
sudo chown -R $USER:$USER /opt/openwebui-oauth
cd /opt/openwebui-oauth

Create docker-compose.yml:

cat > docker-compose.yml <<'YAML'
services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    volumes:
      - ollama:/root/.ollama
    networks:
      - ai
    # CPU-only by default. If you later move to GPU, change runtime settings accordingly.

  openwebui:
    image: ghcr.io/open-webui/open-webui:latest
    container_name: openwebui
    restart: unless-stopped
    environment:
      - OLLAMA_BASE_URL=http://ollama:11434
      # Optional hardening defaults:
      - WEBUI_AUTH=true
      - ENABLE_SIGNUP=false
      - DEFAULT_USER_ROLE=user
    volumes:
      - openwebui:/app/backend/data
    depends_on:
      - ollama
    networks:
      - ai

  oauth2-proxy:
    image: quay.io/oauth2-proxy/oauth2-proxy:latest
    container_name: oauth2-proxy
    restart: unless-stopped
    command: ["--config=/etc/oauth2-proxy/oauth2-proxy.cfg"]
    volumes:
      - ./oauth2-proxy.cfg:/etc/oauth2-proxy/oauth2-proxy.cfg:ro
    networks:
      - ai

networks:
  ai:

volumes:
  ollama:
  openwebui:
YAML

Now create oauth2-proxy.cfg. Use either the Google or GitHub version below.

Google config (email allowlist)

cat > oauth2-proxy.cfg <<'CFG'
http_address = "0.0.0.0:4180"

provider = "google"
client_id = "REPLACE_WITH_GOOGLE_CLIENT_ID"
client_secret = "REPLACE_WITH_GOOGLE_CLIENT_SECRET"
redirect_url = "https://chat.example.com/oauth2/callback"

# Session cookie
cookie_secret = "REPLACE_WITH_YOUR_COOKIE_SECRET"
cookie_secure = true
cookie_httponly = true
cookie_samesite = "lax"

# Security defaults
email_domains = ["*"]
# Recommended: restrict access. Pick one:
# allowed_emails_file = "/etc/oauth2-proxy/allowed_emails.txt"
# google_groups = ["your-team@yourcompany.com"]

# Pass identity to upstream
set_xauthrequest = true
pass_authorization_header = true
pass_access_token = false

# Reverse proxy mode behind Nginx
reverse_proxy = true

# Upstream is Open WebUI inside the Docker network
upstreams = ["http://openwebui:8080/"]

# Optional: make the login prompt clearer
skip_provider_button = false
CFG

GitHub config (org/team-friendly)

cat > oauth2-proxy.cfg <<'CFG'
http_address = "0.0.0.0:4180"

provider = "github"
client_id = "REPLACE_WITH_GITHUB_CLIENT_ID"
client_secret = "REPLACE_WITH_GITHUB_CLIENT_SECRET"
redirect_url = "https://chat.example.com/oauth2/callback"

cookie_secret = "REPLACE_WITH_YOUR_COOKIE_SECRET"
cookie_secure = true
cookie_httponly = true
cookie_samesite = "lax"

# Restrict access. Choose at least one restriction method:
# email_domains = ["yourcompany.com"]
# github_org = "your-github-org"

set_xauthrequest = true
pass_authorization_header = true
reverse_proxy = true

upstreams = ["http://openwebui:8080/"]
CFG

Don’t leave access wide open.

For Google, “internal” plus a group restriction is usually the cleanest.

For GitHub, restrict to an org if you can.

Bring the stack up:

docker compose up -d
docker compose ps

Sanity check from the VPS itself:

curl -sS http://127.0.0.1:4180/ping || true
docker logs --tail=80 oauth2-proxy

Step 6: Put Nginx in front (TLS + auth enforcement)

Nginx terminates TLS on the host and proxies into OAuth2 Proxy.

To keep the surface area small, bind OAuth2 Proxy to localhost only.

Nginx will talk to it on 127.0.0.1.

Edit your Compose file to bind OAuth2 Proxy to localhost by adding ports:

perl -0777 -i -pe 's/container_name: oauth2-proxy\n    restart: unless-stopped/container_name: oauth2-proxy\n    restart: unless-stopped\n    ports:\n      - "127.0.0.1:4180:4180"/s' docker-compose.yml

docker compose up -d

Install Nginx and Certbot:

sudo apt update
sudo apt install -y nginx certbot python3-certbot-nginx

Create an Nginx server block:

sudo tee /etc/nginx/sites-available/chat.example.com > /dev/null <<'NGINX'
server {
  listen 80;
  server_name chat.example.com;

  location /.well-known/acme-challenge/ {
    root /var/www/html;
  }

  location / {
    return 301 https://$host$request_uri;
  }
}
NGINX

Enable it:

sudo ln -s /etc/nginx/sites-available/chat.example.com /etc/nginx/sites-enabled/chat.example.com
sudo nginx -t
sudo systemctl reload nginx

Issue TLS cert:

sudo certbot --nginx -d chat.example.com

Now replace the HTTPS server block with a config that forces OAuth and sets safe proxy headers:

sudo tee /etc/nginx/snippets/openwebui-oauth2-proxy.conf > /dev/null <<'NGINX'
# Send everything to OAuth2 Proxy, which then forwards to Open WebUI.
# This keeps auth logic in one place.

# Hard limit request bodies to reduce accidental huge uploads.
client_max_body_size 25m;

# Basic security headers. Tune CSP if you embed or customize the UI.
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options SAMEORIGIN always;
add_header Referrer-Policy no-referrer always;
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;

# OAuth2 Proxy endpoints
location /oauth2/ {
  proxy_pass http://127.0.0.1:4180;
  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Scheme $scheme;
  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

# Main app traffic
location / {
  proxy_pass http://127.0.0.1:4180;
  proxy_http_version 1.1;

  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Scheme $scheme;
  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

  # WebSockets (Open WebUI uses them)
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection $connection_upgrade;

  # Timeouts for long responses from the model
  proxy_read_timeout 3600;
  proxy_send_timeout 3600;
}
NGINX

Now update the site config. Certbot may have created it already.

Edit the HTTPS server section to include the snippet:

sudo tee /etc/nginx/sites-available/chat.example.com > /dev/null <<'NGINX'
map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}

server {
  listen 80;
  server_name chat.example.com;

  location /.well-known/acme-challenge/ { root /var/www/html; }
  location / { return 301 https://$host$request_uri; }
}

server {
  listen 443 ssl http2;
  server_name chat.example.com;

  ssl_certificate /etc/letsencrypt/live/chat.example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/chat.example.com/privkey.pem;

  include /etc/nginx/snippets/openwebui-oauth2-proxy.conf;
}
NGINX

Reload Nginx:

sudo nginx -t
sudo systemctl reload nginx

Step 7: Test the login flow (and verify it’s actually protected)

Visit https://chat.example.com. You should bounce to Google or GitHub.

After authentication, you should return to the UI.

Run these quick checks before you invite anyone else:

  • Incognito test: you should get prompted to log in again.
  • Direct container access: Open WebUI should not be reachable from the public internet. It isn’t published, so it should be private by default.
  • Cookie flags: in browser dev tools, the OAuth2 Proxy cookie should be Secure and HttpOnly.

On the server, confirm Nginx only talks to the proxy on localhost:

sudo ss -lntp | egrep ':(80|443|4180)\b' || true

You should see 4180 bound to 127.0.0.1, not 0.0.0.0.

Practical hardening for a shared team UI

Most self-hosted chat UIs fail in the same way: they run, but they’re too permissive.

Lock these down before you treat it like an internal tool.

1) Restrict who can sign in

OAuth login proves identity. It doesn’t automatically decide who gets access.

Add at least one restriction rule.

  • Google Workspace: use an “internal” consent screen and restrict to a group.
  • GitHub: restrict by org membership (github_org).
  • Email domain allowlist: workable, but weaker than org/group checks.

2) Keep Open WebUI’s own auth enabled

OAuth2 Proxy guards the front door. Open WebUI auth still matters for roles.

It also helps with damage control if you later expose the service by mistake.

In the Compose file above, WEBUI_AUTH=true and ENABLE_SIGNUP=false keep things predictable.

3) Add rate limiting on Nginx (small, but effective)

OAuth endpoints attract bot traffic. Rate limiting won’t stop a determined attacker.

It does reduce noise and keeps your logs readable.

Add to /etc/nginx/nginx.conf inside the http {} block:

limit_req_zone $binary_remote_addr zone=oauth:10m rate=10r/s;

Then in the location /oauth2/ block in the snippet:

limit_req zone=oauth burst=20 nodelay;

Reload Nginx:

sudo nginx -t && sudo systemctl reload nginx

4) Keep updates boring (watchtower or a scheduled pull)

Open WebUI and OAuth2 Proxy change fast.

Avoid the “it updated itself and now it’s down” scenario.

If you automate updates, make them observable and easy to roll back.

HostMyCode has a solid approach using Watchtower: Docker Compose auto-updates with Watchtower on a VPS.

Operational notes: models, disk growth, and timeouts

This guide is about access control.

Day-two problems usually come from model storage and long-running requests.

Disk usage creeps up quietly

Ollama models can chew through tens of gigabytes each.

Once a few people start experimenting, it’s easy to fill the disk and drag everything down.

Quick check:

docker exec -it ollama sh -lc 'du -sh /root/.ollama || true'
df -h

If you’re already close to full, follow: Disk full on VPS: find large files and free space safely.

Timeouts matter for long responses

If a model takes 30–120 seconds, default proxy timeouts will cut the connection.

The UI then looks “broken.”

The Nginx snippet sets proxy_read_timeout 3600. Keep it unless you want stricter limits.

CPU-only inference has honest limitations

CPU inference works, but concurrency is limited.

Two users requesting long outputs at once can feel rough.

If this is meant to support team workflows, plan for either more CPU or a GPU host later.

HostMyCode’s managed VPS hosting can help if you want the stack maintained without spending your week on patches and TLS renewals.

Troubleshooting checklist (the stuff that actually breaks)

  • Redirect loop: confirm redirect_url matches https://chat.example.com/oauth2/callback exactly; check Nginx is sending X-Forwarded-Proto.
  • 403 after login: your restriction rule is blocking the user (org/group/email). Check OAuth2 Proxy logs.
  • 502 Bad Gateway: Nginx can’t reach 127.0.0.1:4180. Confirm the port mapping exists and container is healthy.
  • WebUI loads but chats fail: websocket headers missing. Ensure the map $http_upgrade block exists and is referenced.
  • Cookie errors: regenerate cookie_secret and ensure it’s pasted correctly; keep cookie_secure=true behind HTTPS.

Useful logs:

docker logs --tail=200 oauth2-proxy
docker logs --tail=200 openwebui
sudo tail -n 200 /var/log/nginx/access.log
sudo tail -n 200 /var/log/nginx/error.log

Where to go next (without turning this into a bigger project)

Once sign-in is under control, the next improvements tend to fall into three buckets:

  • Private access: run the UI behind a tunnel or VPN for admin-only usage.
  • RAG search: add Qdrant/pgvector so the team can chat with internal docs.
  • Model governance: limit which models can be pulled and who can change system prompts.

If your next step is RAG, don’t improvise the storage and indexing layer.

Start with a known-good path like Build RAG search with Qdrant and Open WebUI on VPS, then keep the same OAuth front door from this tutorial.

If you want this to behave like a dependable internal tool, start with a VPS that won’t run out of RAM or disk the first time someone pulls a larger model. A HostMyCode VPS is a straightforward base for Open WebUI + OAuth2 Proxy, and HostMyCode migrations can help you move an existing stack onto a cleaner server without downtime.

FAQ: Open WebUI OAuth setup on a VPS

Do I still need Open WebUI user accounts if I use OAuth2 Proxy?

For team setups, yes.

OAuth2 Proxy decides who can reach the app. Open WebUI accounts handle roles and per-user settings.

Disable self-signup so you don’t end up with a messy account list.

Can I run OAuth2 Proxy and Open WebUI on the same domain?

Yes. This tutorial keeps everything on chat.example.com.

OAuth2 Proxy serves the /oauth2/ endpoints and forwards all other paths to Open WebUI.

What’s the minimum VPS size that feels usable for a small team?

For the UI and auth layer, 2 vCPU / 4 GB is fine.

For CPU inference that won’t annoy people, plan on 4 vCPU / 8–16 GB RAM and keep model sizes modest.

How do I keep the endpoint private if I don’t want it on the public internet?

Put Nginx behind a tunnel or VPN and only allow trusted identities to reach it.

Start with Cloudflare Tunnel on a VPS, then still keep OAuth2 Proxy for identity control.

Is OAuth2 Proxy enough to “secure” the AI endpoint?

It’s a strong front door, but it’s not the whole security story.

Keep your firewall tight, don’t publish container ports, rate limit OAuth endpoints, and watch logs for repeated failures.

Summary

You now have Open WebUI running on a VPS with HTTPS and a real identity layer in front of it.

OAuth2 Proxy handles the login flow and session cookies.

Nginx terminates TLS and proxies cleanly. Docker Compose keeps the whole thing repeatable.

If you plan to expand into RAG, add a GPU host, or standardize this for multiple teams, start from a stable base and keep changes incremental.

A managed VPS hosting plan can take care of the maintenance grind—patching, TLS renewals, and general server hygiene—so you can focus on models and prompts.

Open WebUI With OAuth2 Proxy On A VPS | HostMyCode