server { listen 80; server_name _; root /usr/share/nginx/html; index index.html; # API requests when accessed via Caddy (prefix already stripped by handle_path) location /api/ { proxy_pass http://api:8522; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $http_x_real_ip; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; proxy_set_header X-CF-Session $http_x_cf_session; client_max_body_size 50m; # PDF uploads and LLM inference can be slow proxy_read_timeout 300s; proxy_send_timeout 300s; } # API requests when accessed directly via pagepiper.circuitforge.tech # VITE_API_BASE=/pagepiper means frontend builds calls as /pagepiper/api/... # Caddy passes these unchanged; nginx strips /pagepiper prefix here. location /pagepiper/api/ { rewrite ^/pagepiper(/api/.*)$ $1 break; proxy_pass http://api:8522; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $http_x_real_ip; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto; proxy_set_header X-CF-Session $http_x_cf_session; client_max_body_size 50m; proxy_read_timeout 300s; proxy_send_timeout 300s; } # Static assets at the /pagepiper/ base — used when Caddy does NOT strip the prefix # (i.e., pagepiper.circuitforge.tech routes, where /pagepiper is the Vite base URL). # ^~ prevents regex asset location from matching first. location ^~ /pagepiper/ { alias /usr/share/nginx/html/; try_files $uri $uri/ /index.html; } location = /index.html { add_header Cache-Control "no-cache, no-store, must-revalidate"; try_files $uri /index.html; } location / { try_files $uri $uri/ /index.html; } location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ { expires 1y; add_header Cache-Control "public, immutable"; } }