Spaces:
Running
Running
events { | |
worker_connections 1024; | |
} | |
http { | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
upstream backend { | |
server 127.0.0.1:8002; | |
} | |
upstream frontend { | |
server 127.0.0.1:3000; | |
} | |
server { | |
listen 7860; | |
server_name localhost; | |
# Handle Next.js Image Optimization API with direct serving fallback | |
location /_next/image { | |
# Extract the image URL from query parameters and redirect internally | |
set $image_path ""; | |
if ($args ~ "url=([^&]+)") { | |
set $image_path $1; | |
} | |
# Remove URL encoding (basic cases) | |
if ($image_path ~ "^%2F(.*)") { | |
set $image_path /$1; | |
} | |
# Internal redirect to serve the image directly | |
if ($image_path != "") { | |
rewrite ^.*$ /public-images$image_path last; | |
} | |
return 404; | |
} | |
# Internal location to serve public images | |
location /public-images/ { | |
internal; | |
alias /app/web/public/; | |
expires 1y; | |
add_header Cache-Control "public, immutable"; | |
} | |
# Serve Next.js static files directly | |
location /_next/static/ { | |
alias /app/web/.next/static/; | |
expires 1y; | |
add_header Cache-Control "public, immutable"; | |
} | |
# Serve public files directly from root (logo, favicon, etc.) | |
location ~ ^/(starfish_logo\.png|nvidia\.png|microsoft_startups\.png|favicon\.ico|robots\.txt|sitemap\.xml)$ { | |
root /app/web/public; | |
expires 1y; | |
add_header Cache-Control "public"; | |
} | |
# Serve amplify-ui.css and other public CSS files | |
location ~ ^/(amplify-ui\.css)$ { | |
root /app/web/public; | |
expires 1y; | |
add_header Cache-Control "public"; | |
} | |
# Handle other public files with /public/ prefix | |
location /public/ { | |
alias /app/web/public/; | |
expires 1y; | |
add_header Cache-Control "public"; | |
} | |
# Direct access to FastAPI docs (bypass Next.js) | |
location /backend-docs { | |
proxy_pass http://backend/docs; | |
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 X-Forwarded-Host $host; | |
proxy_set_header X-Forwarded-Port $server_port; | |
} | |
# Direct access to FastAPI OpenAPI schema (bypass Next.js) | |
location /backend-openapi.json { | |
proxy_pass http://backend/openapi.json; | |
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 X-Forwarded-Host $host; | |
proxy_set_header X-Forwarded-Port $server_port; | |
} | |
# Let Next.js handle all other routes | |
location / { | |
proxy_pass http://frontend; | |
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 X-Forwarded-Host $host; | |
proxy_set_header X-Forwarded-Port $server_port; | |
proxy_buffering off; | |
proxy_redirect off; | |
} | |
} | |
} |