Files
OmniRoute/docs/ops/VM_DEPLOYMENT_GUIDE.md
Diego Rodrigues de Sa e Souza 2afaab52a1 maint: final follow-up cherry-pick #9619 (#9901)
* fix(quality): clears two release/v3.8.50 base-red gates

Unblocks Merge integrity and Docs Gates for every PR against
release/v3.8.50, not just this branch:

- changelog.d/features/9415-newapi-sub2api-aggregator-balance.md had a
  non-standard YAML frontmatter header that no other fragment in the
  tree uses. check-changelog-integrity.mjs reads a fragment's first
  non-blank line to validate it starts with a markdown bullet; the
  frontmatter's leading `---` made that check fail regardless of the
  actual bullet content further down. Removed the frontmatter and
  reformatted the body to match the documented changelog.d/README.md
  bullet convention.
- docs/ops/VM_DEPLOYMENT_GUIDE.md documented OMNIROUTE_MAX_POOL_SIZE
  and OMNIROUTE_DB_POOL_SIZE as tunable env vars, but neither is read
  anywhere in the codebase (confirmed via full-repo grep) — this repo
  uses SQLite, which has no connection-pool concept these vars could
  plausibly control. check:fabricated-docs --strict correctly flags
  fabricated env-var claims; removed the bullet rather than
  implementing a feature to match invented documentation.

* fix(i18n): completes Vietnamese parity, fixes empty migration query

Two more release/v3.8.50 base-red items, both surfaced while chasing
CI failures on unrelated PRs:

- vi.json was missing 8 keys that #9539 (NewAPI/Sub2API aggregator
  balance) added to en.json without a matching i18n:sync-ui run —
  pt-BR.json already had all 8, only Vietnamese drifted. Added
  translations for the 6 provider-settings strings, the feature-flag
  description, and the quota tooltip; verified against
  tests/unit/i18n-vi-completeness.test.ts (parity, placeholder
  preservation, ICU parse — all 5 assertions pass).

- src/lib/db/migrations/120_interception_rules.sql was pure comments
  documenting a no-schema-change key_value namespace, with no
  executable SQL statement — the migration runner logged
  "FAILED: 120_interception_rules — Query contained no valid SQL
  statement" on every fresh DB init. 118_provider_param_filters.sql
  (same pattern, two migrations earlier) already ends with a bare
  `SELECT 1;` no-op for exactly this reason; 120 was just missing it.
  Verified directly against better-sqlite3 that the file now executes
  without error.

* fix(types): clears 6 pre-existing release/v3.8.50 typecheck errors

typecheck:core is its own blocking CI job (quality.yml), separate from
Docs Gates/Merge integrity. Confirmed pre-existing and unrelated to
any current work by branching this worktree directly from
upstream/release/v3.8.50 with no other merges applied.

- accountSemaphore.ts: isBypassed() already excludes null/<=0
  maxConcurrency before ensureGate() is called, but a boolean-
  returning helper isn't a type predicate TS can narrow through.
  Added a targeted `as number` at the one call site, with a comment
  explaining why it's safe.

- combo/comboStructure.ts: two module-scope `const HARD_COMPAT_REASONS`
  declarations with different values — a genuine "can't redeclare"
  compile error, not a narrowing gap. The first (4-item set including
  "output_tokens") had zero usages between its own declaration and the
  second; the second (3-item set, matching the CompatFilterOptions doc
  comment exactly) is what hasHardCapabilityFailure/
  describeCapabilityFilterExhaustion/the third call site all actually
  use. Removed the dead first declaration.

- combo/comboStructure.ts + combo/fusionPanel.ts: both accessed
  `.prompt`/`.model` on a `ComboModelStep | ComboProviderWildcardStep`
  union after only excluding `combo-ref`, but `ComboProviderWildcardStep`
  has neither field — a real latent bug (fusionPanel would have pushed
  `undefined` into a fusion panel for a wildcard step). Narrowed to
  `step.kind === "model"` in comboStructure, and switched to the
  already-existing `getComboModelString()` helper in fusionPanel (which
  correctly resolves to null for unsupported step kinds, mirroring how
  combo-ref is already skipped there). Verified directly via a
  standalone script exercising both branches (wildcard vs. model step).

- combo/quotaStrategies.ts: imported `preferAntigravityConnectionsWithStoredProject`
  from a module that never existed (`../antigravityProjectPersistence.ts`,
  distinct from the real `antigravityProjectPersist.ts`) — the function
  itself was referenced nowhere else in the codebase. Wrote the missing
  implementation: prefers Antigravity connections with a discovered
  `projectId` for reset-aware routing, failing open to the full list
  when none have one yet (per the file's own "Exclude... from reset-aware
  pool" changelog note, softened to a preference — strict exclusion
  would empty the pool entirely for a fleet of freshly-added accounts).
  Verified directly via a standalone script.

- compression/engines/ccr/index.ts: `enforceGlobalBudget(owner, bytes)`
  was called with only `bytes` at one of its two call sites, missing the
  `owner` argument the other call site (and the function's own doc
  comment on preferring the calling principal's LRU eviction) already
  uses correctly. Added the missing `entry.principalId` argument.

- firecrawlQuotaFetcher.ts: `fetchFirecrawlQuota` was annotated to
  return `Promise<QuotaInfo | null>` but every return path constructs a
  `FirecrawlQuota` (QuotaInfo extended with remainingCredits/planCredits/
  extraCreditsInferred/overPlan) — the type the file already defines and
  the type `parseFirecrawlCreditUsage` already correctly returns.
  Widened the annotation to match; `FirecrawlQuota extends QuotaInfo` so
  this stays compatible with the `QuotaFetcher` contract.

npm run typecheck:core and npm run check:dashboard-typecheck both pass
cleanly. A subset of DB-backed tests in this area also fail, but 100%
attributably to an already-tracked, unrelated migration version
collision (134 -> [ccr_blocks, proxy_logs_egress_ip], see
_tasks/features-v3.8.4/9route/POST-MERGE-AUDIT.md) — confirmed by every
failure's stack trace bottoming out at that exact error, not at
anything touched here.

* fix(sse): update stale ALL_ACCOUNTS_INACTIVE test assertions to ALL_TARGETS_SKIPPED

Two combo-routing-engine.test.ts cases assert the pre-dispatch-skip scenario (isModelAvailable always false, zero dispatch attempts) returns ALL_ACCOUNTS_INACTIVE. Production code already distinguishes this case via the recordedAttempts === 0 branch and returns the more precise ALL_TARGETS_SKIPPED -- the tests were never updated when that branch shipped upstream, so they fail on a clean release/v3.8.50 checkout independent of this PR's changes.

* fix(sse): update second stale ALL_ACCOUNTS_INACTIVE assertion (T24)

Same pre-existing upstream test-drift as 038035f93: t23-t24-fallback-resilience.test.ts's T24 case asserts the pre-dispatch-skip scenario returns ALL_ACCOUNTS_INACTIVE, but production code returns the more precise ALL_TARGETS_SKIPPED when recordedAttempts === 0. Caught by this PR's own fresh CI run after the dirty-mergeable-state fix.

* fix(quality): rebaseline combo-routing-engine.test.ts own-comment growth

The ALL_ACCOUNTS_INACTIVE->ALL_TARGETS_SKIPPED fix (58ab721fe) added explanatory comments (+7 lines), pushing the file past its frozen 3457 cap. CI's PR-mode check:file-size caught it; local check-file-size.mjs was not re-run after that specific commit.

* chore(tests): drop explanatory comments on ALL_TARGETS_SKIPPED assertions

Kept the assertion value fix (ALL_ACCOUNTS_INACTIVE -> ALL_TARGETS_SKIPPED); the comments were unnecessary. Reverts the file-size baseline bump these comments caused (combo-routing-engine.test.ts back to its original 3457).

---------

Co-authored-by: Will Gordon <wgordon@redhat.com>
2026-08-09 14:15:53 -03:00

13 KiB

title, version, lastUpdated
title version lastUpdated
OmniRoute — Deployment Guide on VM with Cloudflare 3.8.40 2026-06-28

OmniRoute — Deployment Guide on VM with Cloudflare

🌐 Languages: 🇺🇸 English | 🇧🇷 Português (Brasil) | 🇪🇸 Español | 🇫🇷 Français | 🇮🇹 Italiano | 🇷🇺 Русский | 🇨🇳 中文 (简体) | 🇩🇪 Deutsch | 🇮🇳 हिन्दी | 🇹🇭 ไทย | 🇺🇦 Українська | 🇸🇦 العربية | 🇯🇵 日本語 | 🇻🇳 Tiếng Việt | 🇧🇬 Български | 🇩🇰 Dansk | 🇫🇮 Suomi | 🇮🇱 עברית | 🇭🇺 Magyar | 🇮🇩 Bahasa Indonesia | 🇰🇷 한국어 | 🇲🇾 Bahasa Melayu | 🇳🇱 Nederlands | 🇳🇴 Norsk | 🇵🇹 Português (Portugal) | 🇷🇴 Română | 🇵🇱 Polski | 🇸🇰 Slovenčina | 🇸🇪 Svenska | 🇵🇭 Filipino | 🇨🇿 Čeština

Complete guide to install and configure OmniRoute on a VM (VPS) with domain managed via Cloudflare.


Prerequisites

Item Minimum Recommended
CPU 1 vCPU 2 vCPU
RAM 1 GB 2 GB
Disk 10 GB SSD 25 GB SSD
OS Ubuntu 22.04 LTS Ubuntu 24.04 LTS
Domain Registered on Cloudflare
Docker Docker Engine 24+ Docker 27+

Tested providers: Akamai (Linode), DigitalOcean, Vultr, Hetzner, AWS Lightsail.


1. Configure the VM

1.1 Create the instance

On your preferred VPS provider:

  • Choose Ubuntu 24.04 LTS
  • Select the minimum plan (1 vCPU / 1 GB RAM)
  • Set a strong root password or configure SSH key
  • Note the public IP (e.g., 203.0.113.10)

1.2 Connect via SSH

ssh root@203.0.113.10

1.3 Update the system

apt update && apt upgrade -y

1.4 Install Docker

# Install dependencies
apt install -y ca-certificates curl gnupg

# Add official Docker repository
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 $ (. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt update
apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

1.5 Install nginx

apt install -y nginx

1.6 Configure Firewall (UFW)

ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp    # SSH
ufw allow 80/tcp    # HTTP (redirect)
ufw allow 443/tcp   # HTTPS
ufw enable

Tip

: For maximum security, restrict ports 80 and 443 to Cloudflare IPs only. See the Advanced Security section.


2. Install OmniRoute

2.1 Create configuration directory

mkdir -p /opt/omniroute

2.2 Create environment variables file

cat > /opt/omniroute/.env << 'EOF'
# === Security ===
JWT_SECRET=CHANGE-TO-A-UNIQUE-64-CHAR-SECRET-KEY
INITIAL_PASSWORD=YourSecurePassword123!
API_KEY_SECRET=REPLACE-WITH-ANOTHER-SECRET-KEY
STORAGE_ENCRYPTION_KEY=REPLACE-WITH-THIRD-SECRET-KEY
STORAGE_ENCRYPTION_KEY_VERSION=v1
MACHINE_ID_SALT=CHANGE-TO-A-UNIQUE-SALT
OMNIROUTE_WS_BRIDGE_SECRET=REPLACE-WITH-WS-BRIDGE-SECRET  # REQUIRED em produção: usado pelo Codex Responses WS bridge

# === App ===
PORT=20128
NODE_ENV=production
HOSTNAME=0.0.0.0
DATA_DIR=/app/data
APP_LOG_TO_FILE=true
AUTH_COOKIE_SECURE=true
REQUIRE_API_KEY=false

# === URLs (change to your domain) ===
# Internal server-to-server base URL for scheduled jobs / self-fetches.
BASE_URL=http://127.0.0.1:20128
# Browser-facing URL used for OAuth callbacks, dashboard links, and generated public URLs.
NEXT_PUBLIC_BASE_URL=https://llms.seudominio.com
# Optional explicit public origin override for generated public asset URLs.
# OMNIROUTE_PUBLIC_BASE_URL=https://llms.seudominio.com

# === Cloud Sync (optional) ===
# CLOUD_URL=https://cloud.omniroute.online
# NEXT_PUBLIC_CLOUD_URL=https://cloud.omniroute.online
EOF

⚠️ IMPORTANT: Generate unique secret keys! Use openssl rand -hex 32 for each key.

2.3 Start the container

docker pull diegosouzapw/omniroute:latest

docker run -d \
  --name omniroute \
  --restart unless-stopped \
  --env-file /opt/omniroute/.env \
  -p 20128:20128 \
  -v omniroute-data:/app/data \
  diegosouzapw/omniroute:latest

2.4 Verify that it is running

docker ps | grep omniroute
docker logs omniroute --tail 20

It should display: [DB] SQLite database ready and listening on port 20128.


3. Configure nginx (Reverse Proxy)

3.1 Generate SSL certificate (Cloudflare Origin)

In the Cloudflare dashboard:

  1. Go to SSL/TLS → Origin Server
  2. Click Create Certificate
  3. Keep the defaults (15 years, *.yourdomain.com)
  4. Copy the Origin Certificate and the Private Key
mkdir -p /etc/nginx/ssl

# Paste the certificate
nano /etc/nginx/ssl/origin.crt

# Paste the private key
nano /etc/nginx/ssl/origin.key

chmod 600 /etc/nginx/ssl/origin.key

3.2 Nginx Configuration

cat > /etc/nginx/sites-available/omniroute << 'NGINX'
# Default server — blocks direct access via IP
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    ssl_certificate     /etc/nginx/ssl/origin.crt;
    ssl_certificate_key /etc/nginx/ssl/origin.key;
    server_name _;
    return 444;
}

# OmniRoute — HTTPS
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name llms.yourdomain.com;  # Change to your domain

    ssl_certificate     /etc/nginx/ssl/origin.crt;
    ssl_certificate_key /etc/nginx/ssl/origin.key;
    ssl_protocols TLSv1.2 TLSv1.3;

    client_max_body_size 100M;

    location / {
        proxy_pass http://127.0.0.1:20128;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-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;

        # WebSocket support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        # SSE (Server-Sent Events) — streaming AI responses
        proxy_buffering off;
        proxy_cache off;
        proxy_read_timeout 600s;
        proxy_send_timeout 600s;
    }
}

# HTTP → HTTPS redirect
server {
    listen 80;
    listen [::]:80;
    server_name llms.yourdomain.com;
    return 301 https://$server_name$request_uri;
}
NGINX

Keep reverse-proxy stream timeouts aligned with your OmniRoute timeout env vars. If you raise FETCH_TIMEOUT_MS / STREAM_IDLE_TIMEOUT_MS, raise proxy_read_timeout / proxy_send_timeout above the same threshold.

OmniRoute uses NEXT_PUBLIC_BASE_URL as the canonical browser-facing origin for OAuth callbacks and generated public links. Authenticated dashboard writes use same-origin requests plus session-bound CSRF protection, so they do not require a static public base URL. The X-Forwarded-* headers above are still useful routing metadata, but they are not a replacement for setting the explicit public URL when OAuth or generated browser links need one. Only enable OMNIROUTE_TRUST_PROXY if OmniRoute is not directly reachable by clients and your proxy strips/rebuilds incoming forwarded headers.

3.3 Enable and Test

# Remove default configuration
rm -f /etc/nginx/sites-enabled/default

# Enable OmniRoute
ln -sf /etc/nginx/sites-available/omniroute /etc/nginx/sites-enabled/omniroute

# Test and reload
nginx -t && systemctl reload nginx

4. Configure Cloudflare DNS

4.1 Add DNS record

In the Cloudflare dashboard → DNS:

Type Name Content Proxy
A llms 203.0.113.10 (VM IP) Proxied

4.2 Configure SSL

Under SSL/TLS → Overview:

  • Mode: Full (Strict)

Under SSL/TLS → Edge Certificates:

  • Always Use HTTPS: On
  • Minimum TLS Version: TLS 1.2
  • Automatic HTTPS Rewrites: On

4.3 Testing

curl -sI https://llms.seudominio.com/health
# Should return HTTP/2 200

5. Operations and Maintenance

Upgrade to a new version

docker pull diegosouzapw/omniroute:latest
docker stop omniroute && docker rm omniroute
docker run -d --name omniroute --restart unless-stopped \
  --env-file /opt/omniroute/.env \
  -p 20128:20128 \
  -v omniroute-data:/app/data \
  diegosouzapw/omniroute:latest

View logs

docker logs -f omniroute          # Real-time stream
docker logs omniroute --tail 50   # Last 50 lines

Manual database backup

# Copy data from the volume to the host
docker cp omniroute:/app/data ./backup-$(date +%F)

# Or compress the entire volume
docker run --rm -v omniroute-data:/data -v $(pwd):/backup \
  alpine tar czf /backup/omniroute-data-$(date +%F).tar.gz /data

Restore from backup

docker stop omniroute
docker run --rm -v omniroute-data:/data -v $(pwd):/backup \
  alpine sh -c "rm -rf /data/* && tar xzf /backup/omniroute-data-YYYY-MM-DD.tar.gz -C /"
docker start omniroute

6. Advanced Security

Restrict nginx to Cloudflare IPs

cat > /etc/nginx/cloudflare-ips.conf << 'CF'
# Cloudflare IPv4 ranges — update periodically
# https://www.cloudflare.com/ips-v4/
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/13;
set_real_ip_from 104.24.0.0/14;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 131.0.72.0/22;
real_ip_header CF-Connecting-IP;
CF

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

include /etc/nginx/cloudflare-ips.conf;

Install fail2ban

apt install -y fail2ban
systemctl enable fail2ban
systemctl start fail2ban

# Check status
fail2ban-client status sshd

Block direct access to the Docker port

# Prevent direct external access to port 20128
iptables -I DOCKER-USER -p tcp --dport 20128 -j DROP
iptables -I DOCKER-USER -i lo -p tcp --dport 20128 -j ACCEPT

# Persist the rules
apt install -y iptables-persistent
netfilter-persistent save

7. Deploy to Cloudflare Workers (Optional)

For remote access via Cloudflare Workers (without exposing the VM directly):

# In the local repository
cd omnirouteCloud
npm install
npx wrangler login
npx wrangler deploy

See also TUNNELS_GUIDE.md for the in-repo Cloudflare Tunnel walkthrough. The standalone omnirouteCloud/ worker lives in a separate companion repo.


Port Summary

Port Service Access
22 SSH Public (with fail2ban)
80 nginx HTTP Redirect → HTTPS
443 nginx HTTPS Via Cloudflare Proxy
20128 OmniRoute Localhost only (via nginx)

Low-Memory / Small VPS Optimization

For deployments on small VPS instances (1 GB RAM or less):

  • Disable background services — set OMNIROUTE_DISABLE_BACKGROUND_SERVICES=1 to skip scheduler, MCP server, and periodic maintenance tasks. See docs/reference/ENVIRONMENT.md.
  • Use SQLite WAL mode — enabled by default, reduces peak memory during concurrent reads.
  • Avoid next build on the VPS — build locally and deploy the standalone output (.next/standalone/).
  • Monitor with top / free -m — OmniRoute typically uses 200-400 MB RSS at idle on a 1 GB VM.