From b27158ef034bccec750ff31868421c667db18246 Mon Sep 17 00:00:00 2001 From: SysVis AI Date: Sun, 28 Dec 2025 20:37:32 +0700 Subject: [PATCH] fix: dynamic DNS for optional ollama proxy --- nginx.conf | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/nginx.conf b/nginx.conf index 0c16e6a..139c096 100644 --- a/nginx.conf +++ b/nginx.conf @@ -13,15 +13,21 @@ server { } # Proxy Ollama API requests - # This solves Mixed Content (HTTPS -> HTTP) and CORS issues + # Uses dynamic resolution so container can start without Ollama available location /api/ { - proxy_pass http://ollama:11434/api/; + # Use Docker's internal DNS resolver with a short cache + resolver 127.0.0.11 valid=10s ipv6=off; + + # Use a variable to force runtime DNS resolution (not startup) + set $upstream_ollama http://ollama:11434; + proxy_pass $upstream_ollama/api/; + 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; - # CORS headers (redundant if OLLAMA_ORIGINS is set, but good for safety) + # CORS headers add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always; @@ -32,5 +38,9 @@ server { add_header 'Content-Length' 0; return 204; } + + # Handle case where Ollama isn't available + proxy_connect_timeout 5s; + proxy_read_timeout 300s; } }