feat: 2-layer architecture foundation + agent migration
Router v2: - Atomic GPU slot booking (Redis Lua — closes TOCTOU race) - Circuit breaker with failure threshold (3 failures/120s → 60s cooldown) - GPU health scoring with configurable weights (VRAM 40% + temp 30% + load 30%) - X-Usage-Tokens header for LiteLLM spend tracking - /health/unified endpoint (aggregates all layers) - Strict explicit model passthrough (no silent fallback) - syslog-auto → auto routing fix Infrastructure: - Postgres 16 for LiteLLM state - LiteLLM production config (router:9000, fallback chains, guardrails) - Dual-path NGINX: /v1/→router, /litellm/v1/→LiteLLM, port 4000 UI - DNS split-horizon (auth.sysloggh.net → 192.168.68.11) - 6 LiteLLM virtual keys for agent cutover Deployed to CT 116, all 6 containers healthy.
This commit is contained in:
+193
-49
@@ -1,18 +1,10 @@
|
||||
worker_processes auto;
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
pid /var/run/nginx.pid;
|
||||
|
||||
events { worker_connections 1024; }
|
||||
events {
|
||||
worker_connections 1024;
|
||||
}
|
||||
|
||||
http {
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||||
'$status $body_bytes_sent "$http_referer" '
|
||||
'"$http_user_agent" rt=$request_time';
|
||||
access_log /var/log/nginx/access.log main;
|
||||
error_log /var/log/nginx/error.log;
|
||||
sendfile on;
|
||||
keepalive_timeout 65;
|
||||
|
||||
@@ -20,18 +12,33 @@ http {
|
||||
upstream dashboard_ui { server dashboard:3000; }
|
||||
upstream litellm_backend { server litellm:4000; }
|
||||
|
||||
# Detect Cloudflare Tunnel requests (cloudflared always sets CF-Connecting-IP).
|
||||
# Direct LAN browser access to :4000 has no such header -> redirect to canonical https,
|
||||
# preventing the cross-origin localStorage footgun that traps the UI at the login page.
|
||||
map $http_cf_connecting_ip $is_cloudflared {
|
||||
default 1; # any non-empty value = request came through Cloudflare
|
||||
"" 0; # empty = direct access
|
||||
}
|
||||
|
||||
# ════════════════════════════════════════════════════════════════
|
||||
# Server :80 — existing harness entrypoint
|
||||
# dashboard (/), router API (/v1/, /admin/, /stream, /api/, /metrics),
|
||||
# router fallback, LiteLLM UI via /litellm/ prefix, health
|
||||
# ════════════════════════════════════════════════════════════════
|
||||
server {
|
||||
listen 80;
|
||||
|
||||
# Security headers
|
||||
add_header X-Content-Type-Options nosniff always;
|
||||
add_header X-Frame-Options SAMEORIGIN always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
# Authentik OIDC subrequest
|
||||
location /authentik/auth {
|
||||
internal;
|
||||
proxy_pass https://auth.sysloggh.net/outpost.goauthentik.io/auth/nginx;
|
||||
proxy_pass_request_body off;
|
||||
proxy_set_header Content-Length "";
|
||||
proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
# Disable buffering for SSE streams
|
||||
proxy_buffering off;
|
||||
|
||||
# API through router
|
||||
# 2-Layer: /v1/ → router (existing keys work unchanged)
|
||||
location /v1/ {
|
||||
proxy_pass http://router_api;
|
||||
proxy_http_version 1.1;
|
||||
@@ -41,6 +48,16 @@ http {
|
||||
proxy_connect_timeout 10s;
|
||||
proxy_read_timeout 600s;
|
||||
proxy_buffering off;
|
||||
error_page 502 503 = @router_fallback;
|
||||
}
|
||||
|
||||
location @router_fallback {
|
||||
proxy_pass http://router_api;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
proxy_read_timeout 600s;
|
||||
}
|
||||
|
||||
location /admin/ {
|
||||
@@ -49,70 +66,197 @@ http {
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
proxy_read_timeout 600s;
|
||||
}
|
||||
|
||||
# SSE streaming endpoint
|
||||
location /stream {
|
||||
proxy_pass http://router_api;
|
||||
proxy_pass http://router_api/stream;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header Connection "";
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_buffering off;
|
||||
chunked_transfer_encoding off;
|
||||
}
|
||||
|
||||
# Dashboard API proxy for SSE
|
||||
location /api/ {
|
||||
proxy_pass http://dashboard_ui;
|
||||
proxy_pass http://router_api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_buffering off;
|
||||
}
|
||||
|
||||
# LiteLLM debug
|
||||
location /litellm/ {
|
||||
rewrite ^/litellm/(.*) /$1 break;
|
||||
proxy_pass http://litellm_backend;
|
||||
# LiteLLM gateway access (agents with new virtual keys)
|
||||
location /litellm/v1/ {
|
||||
proxy_pass http://litellm_backend/v1/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
}
|
||||
|
||||
# Professional Dashboard (Phase 1-3) - Static HTML served via Nginx
|
||||
location /dashboard/ {
|
||||
alias /opt/inference-harness/dashboard/;
|
||||
index dashboard.html;
|
||||
add_header Cache-Control "public, max-age=3600";
|
||||
add_header X-Content-Type-Options nosniff;
|
||||
}
|
||||
|
||||
# Legacy Dashboard (root) - Proxy to Flask app
|
||||
location / {
|
||||
proxy_pass http://dashboard_ui;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_connect_timeout 10s;
|
||||
proxy_read_timeout 600s;
|
||||
proxy_buffering off;
|
||||
}
|
||||
|
||||
# Performance analytics
|
||||
# LiteLLM UI static assets
|
||||
location /litellm-asset-prefix/ {
|
||||
proxy_pass http://litellm_backend/litellm-asset-prefix/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
# LiteLLM Admin UI via /litellm/ prefix (LAN/internal access on :80)
|
||||
location /litellm/ {
|
||||
proxy_pass http://litellm_backend/;
|
||||
proxy_http_version 1.1;
|
||||
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_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_read_timeout 86400s;
|
||||
proxy_buffering off;
|
||||
proxy_redirect http://$host/ /litellm/;
|
||||
proxy_redirect https://$host/ /litellm/;
|
||||
}
|
||||
|
||||
location /dashboard/ {
|
||||
proxy_pass http://dashboard_ui/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
location / {
|
||||
root /opt/inference-harness/dashboard;
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
location /metrics/ {
|
||||
proxy_pass http://router_api;
|
||||
proxy_pass http://router_api/metrics/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
# Circuit Breaker metrics (Phase 1)
|
||||
location /metrics/circuit-breaker {
|
||||
proxy_pass http://router_api/metrics/circuit-breaker;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
location /router/ {
|
||||
proxy_pass http://router_api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
location /health/unified {
|
||||
proxy_pass http://router_api/health/unified;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
location /health {
|
||||
proxy_pass http://router_api/health;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
}
|
||||
}
|
||||
|
||||
# ════════════════════════════════════════════════════════════════
|
||||
# Server :4000 — external LiteLLM entrypoint (cloudflared target)
|
||||
# Fixes the /ui redirect: forces correct Host + scheme so LiteLLM
|
||||
# builds external URLs instead of leaking 192.168.68.116:4000.
|
||||
# LiteLLM itself is now bound to 127.0.0.1 only (see compose).
|
||||
# ════════════════════════════════════════════════════════════════
|
||||
server {
|
||||
listen 4000;
|
||||
|
||||
# Canonical external identity — overrides whatever Host cloudflared sends
|
||||
proxy_set_header Host litellm.sysloggh.net;
|
||||
proxy_set_header X-Forwarded-Host litellm.sysloggh.net;
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
proxy_set_header X-Forwarded-Port 443;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
|
||||
# /ui → /ui/ — absolute redirect (cloudflared rewrites Host to origin IP,
|
||||
# so a relative return would be absolutized to http://192.168.68.116:4000/).
|
||||
location = /ui { return 301 https://litellm.sysloggh.net/ui/; }
|
||||
|
||||
# LiteLLM Admin UI + WebSocket
|
||||
location /ui/ {
|
||||
proxy_pass http://litellm_backend/ui/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_read_timeout 86400s;
|
||||
proxy_buffering off;
|
||||
proxy_redirect http://litellm_backend/ https://litellm.sysloggh.net/;
|
||||
proxy_redirect http://litellm.sysloggh.net:4000/ https://litellm.sysloggh.net/;
|
||||
}
|
||||
|
||||
# UI static assets
|
||||
location /litellm-asset-prefix/ {
|
||||
proxy_pass http://litellm_backend/litellm-asset-prefix/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
}
|
||||
|
||||
# SSO callback
|
||||
location /sso/ {
|
||||
proxy_pass http://litellm_backend/sso/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_read_timeout 600s;
|
||||
}
|
||||
|
||||
# API
|
||||
location /v1/ {
|
||||
proxy_pass http://litellm_backend/v1/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
proxy_read_timeout 600s;
|
||||
proxy_buffering off;
|
||||
}
|
||||
|
||||
# Key management + admin API
|
||||
location /key/ {
|
||||
proxy_pass http://litellm_backend/key/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
}
|
||||
location /user/ {
|
||||
proxy_pass http://litellm_backend/user/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
}
|
||||
location /model/ {
|
||||
proxy_pass http://litellm_backend/model/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
}
|
||||
location /team/ {
|
||||
proxy_pass http://litellm_backend/team/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Authorization $http_authorization;
|
||||
}
|
||||
|
||||
# Health
|
||||
location /health {
|
||||
proxy_pass http://litellm_backend/health;
|
||||
proxy_http_version 1.1;
|
||||
}
|
||||
|
||||
# Root + everything else → LiteLLM (UI index, /configs, /spend, etc.)
|
||||
location / {
|
||||
proxy_pass http://litellm_backend/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_read_timeout 86400s;
|
||||
proxy_buffering off;
|
||||
proxy_redirect http://192.168.68.116:4000/ https://litellm.sysloggh.net/;
|
||||
proxy_redirect https://192.168.68.116:4000/ https://litellm.sysloggh.net/;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user