Here’s a quick checklist to debug:
Check proxy_pass
configuration:
Ensure that proxy_pass points to http://ip:port/
without including the subpath (e.g., /book/
). If you include the subpath, FastAPI won't match routes properly and will return 404.
Verify trailing slash handling:
FastAPI distinguishes between /book
and /book/
. Missing or inconsistent slashes can cause 404 errors. Make sure your URLs are consistent, or add a rewrite rule in Nginx to enforce a trailing slash.
Check CORS settings: If accessing from browsers, CORS misconfiguration can prevent requests from reaching the backend, appearing like 404s. Make sure you add proper CORS middleware to your FastAPI applications.
Ensure backend service availability:
Confirm that your FastAPI apps are running, listening on 0.0.0.0
(not 127.0.0.1
), and reachable at the specified IP and port. You can test direct access using curl or a browser to verify backend health.
If the issue persists, can you show your current Nginx config? It will help pinpoint the problem faster.