Files
AI_CPA/nginx/default.conf
T

105 lines
4.1 KiB
Plaintext

server {
listen 80;
server_name aiindiacpa.duckdns.org 147.93.168.145;
# ── Certbot ACME Challenge ───────────────────────────────────────────────
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
# Redirect all HTTP traffic to HTTPS (uncomment when SSL certs are generated)
# location / {
# return 301 https://$host$request_uri;
# }
# Max upload size — matches backend 10MB limit with buffer
client_max_body_size 15m;
# ── Static CSS (served directly from dist, no FastAPI hop) ───────────────
location /css/ {
root /usr/share/nginx/html;
expires 7d;
add_header Cache-Control "public, no-transform";
try_files $uri =404;
}
# ── Vite JS/CSS bundle assets (hashed filenames — cache forever) ─────────
location /assets/ {
root /usr/share/nginx/html;
expires 1y;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
# ── Static images served from dist ───────────────────────────────────────
location /images/ {
root /usr/share/nginx/html;
expires 7d;
add_header Cache-Control "public, no-transform";
try_files $uri =404;
}
# ── Favicon and root-level static files ──────────────────────────────────
location = /favicon.svg {
root /usr/share/nginx/html;
expires 7d;
}
location = /icons.svg {
root /usr/share/nginx/html;
expires 7d;
}
# ── User-uploaded files (documents stored on VPS disk) ───────────────────
# Proxied through FastAPI for auth token validation — never served directly
location /api/upload/file/ {
proxy_pass http://app:8000;
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;
# Allow larger responses for file downloads
proxy_buffering off;
proxy_read_timeout 120s;
}
# ── All API routes → FastAPI ──────────────────────────────────────────────
location /api/ {
proxy_pass http://app:8000;
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_read_timeout 60s;
proxy_send_timeout 60s;
}
# ── Health check (bypass FastAPI for load balancer pings) ────────────────
location = /health {
proxy_pass http://app:8000;
proxy_set_header Host $host;
}
# ── SPA fallback — serve index.html for all other routes ─────────────────
# React Router handles the actual routing client-side
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}
}
# ── HTTPS Server Block ───────────────────────────────────────────────────
# Uncomment this block after generating SSL certificates via Certbot
# server {
# listen 443 ssl;
# server_name aiindiacpa.duckdns.org 147.93.168.145;
#
# ssl_certificate /etc/letsencrypt/live/aiindiacpa.duckdns.org/fullchain.pem;
# ssl_certificate_key /etc/letsencrypt/live/aiindiacpa.duckdns.org/privkey.pem;
#
# # (Include the rest of the location blocks from port 80 here)
# }