Framework routes and static assets
Decide who owns each URL
A single-page application (SPA) loads an HTML shell and uses browser JavaScript to interpret navigation. A server-rendered app builds HTML in the backend for each relevant request. An API returns structured data or errors. A reverse proxy must preserve these distinctions instead of returning the SPA shell for every unknown path. The lab has a static shell placeholder rather than a full JavaScript router.
Make the fallback narrow
root www;location ^~ /assets/ { try_files $uri =404; }location ^~ /ui/ { try_files $uri /index.html; }location = /index.html { add_header Cache-Control no-cache; }location ^~ /api/ { proxy_pass http://127.0.0.1:19030/; }location ^~ /server/ { proxy_pass http://127.0.0.1:19031/; }location / { return 404; }The UI fallback internally serves index.html, so a client navigation to /ui/orders receives the shell. A missing CSS asset returns 404 instead of HTML; /api/missing stays an upstream 404. /server/reports returns the WSGI-rendered page. Keep app source, configuration, uploads and credentials outside www.
/ui/orders 200 HTML shell/assets/site.css 200 text/css/assets/missing.css 404/api/items 200 JSON/api/missing 404 JSON/server/reports 200 HTML/server/missing 404 textBase paths and URL generation
A URI suffix on proxy_pass changes the path delivered upstream. If the application needs to generate links under /server/, configure its external mount path as well; WSGI SCRIPT_NAME and ASGI root_path describe mount information, but a proxy rewrite alone does not set them automatically. The fixture returns no generated links. Check redirects, absolute asset URLs, cookies and framework trust settings with the actual application.
location /server/ { proxy_pass http://127.0.0.1:19031;}This forwards /server/reports unchanged; the current toy WSGI app would return 404 because it expects /reports. Choose one contract, not both.
Assets and uploads
Serve only the application build output designated public. Do not mount the entire source repository. Use content-hashed immutable assets when the build supports them and revalidate the HTML shell. Uploads should be handled by the app with authorization, type and size validation, and non-executable storage outside the public directory.
Nginx may reject larger bodies with 413; this does not validate file content or authorize uploads. Set an appropriate application limit too. The lab has no upload route; 64 KiB is a small fixture bound, not a production recommendation.
Practice
Predict the status, content type and owner for /api/missing, /ui/orders and /assets/missing.css. Explain how a catch-all SPA fallback would make API diagnostics harder.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Framework routes and static assets
Separate static files, client-side navigation, server rendering and API responses without hiding application errors.
What should /api/missing return in the lab?
Which path should be eligible for SPA fallback?
What should a missing static CSS file return?
What must be considered when mounting an app under /server/?
Where should private uploads normally be stored?