Nginx: reverse proxy returns 404 — location /api/ { proxy_pass http://app:3000/; } strips the prefix (or keeps it)
Whether proxy_pass has a URI part decides if the matched prefix is stripped, so the backend receives an unexpected path.
nginx proxy_pass trailing slash 404proxy_pass strips location prefix 404 upstreamnginx reverse proxy 404 Not Found backend pathnginx proxy_pass with URI path replacednginx location /api/ proxy_pass 404 Meaning
proxy_pass http://app:3000; (no URI) passes the original path unchanged. proxy_pass http://app:3000/; (trailing slash) replaces the matched location prefix with /. So /api/users becomes /users. Make location and proxy_pass slashes consistent with what the backend expects, and test with curl -v.
Common causes
- Trailing slash on proxy_pass stripping
/api - Missing slash passing
/apito a backend that expects/ - Regex locations with URI in proxy_pass (invalid)
- Variables in proxy_pass changing behaviour
- Rewrite + proxy_pass combination
⚡ Quick fix
- Decide: pass-through (
proxy_pass http://app;) or strip (location /api/ { proxy_pass http://app/; }) - Use
rewrite ^/api/(.*)$ /$1 break;for explicit mapping - Check the backend access log for the received path
Detailed fix by platform
Linux
curl -v https://example.com/api/usersand compare with the backend log line
How to diagnose
- Slash — proxy_pass trailing?
- Path — What backend sees?
- Rewrite — Needed?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Nginx / Apache
- nginx: [emerg] unknown directive Nginx: nginx: [emerg] unknown directive "x" in /etc/nginx/sites-enabled/x:12 — configuration file test failed
- upstream timed out Nginx: upstream timed out (110: Connection timed out) while reading response header from upstream
- AH00558 Apache: AH00558: apache2: Could not reliably determine the server's fully qualified domain name
Other ways to find it
Where this error sits
Origin: Edge & web server. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026