Sys-Arc-Visl/nginx.conf

45 lines
1.8 KiB
Nginx Configuration File

server {
listen 80;
# Enable gzip compression
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
# Root directory for the app
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
# Proxy Ollama API requests (optional - only works when ollama container is running)
# This solves Mixed Content (HTTPS -> HTTP) and CORS issues
location /api/ {
# Use Docker's internal DNS resolver with short timeout
# This allows nginx to start even if ollama is not running
resolver 127.0.0.11 valid=30s ipv6=off;
set $ollama_upstream "ollama:11434";
proxy_pass http://$ollama_upstream/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;
# Timeout settings for when ollama is unavailable
proxy_connect_timeout 5s;
proxy_read_timeout 300s;
# CORS headers (redundant if OLLAMA_ORIGINS is set, but good for safety)
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;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain; charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
}
}