fix: production deployment fixes
- .env: MYSQL_HOST=db (Docker service name, not localhost) - .env: ALLOWED_ORIGINS includes bookkeepro.net + IP - docker-compose.yml: add nginx service, fix MySQL user/password env vars, expose app on port 8000 internally only, nginx on port 80 - nginx/default.conf: serve /css /assets /images directly from dist, proxy /api/* to FastAPI, SPA fallback via try_files - main.py: remove duplicate /dist mount, hide API docs in production, clean up static mount logic - requirements.txt: add pypdf==4.3.1 (was missing, used by ai.py)
This commit is contained in:
+71
-13
@@ -2,22 +2,80 @@ server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
client_max_body_size 25m;
|
||||
# Max upload size — matches backend 10MB limit with buffer
|
||||
client_max_body_size 15m;
|
||||
|
||||
location ~ ^/(css|js|images)/ {
|
||||
# ── Static CSS (served directly from dist, no FastAPI hop) ───────────────
|
||||
location /css/ {
|
||||
root /usr/share/nginx/html;
|
||||
expires 30d;
|
||||
expires 7d;
|
||||
add_header Cache-Control "public, no-transform";
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location / {
|
||||
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_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
# ── 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user