proxy_pass with a URI changes the path (404 from upstream) Nginx / Apache Origin: Edge & web server OSI layer 7 · Application Last updated 5 Nov 2026

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.

Exact message you may see 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
Seen on: Nginx Linux

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 /api to a backend that expects /
  • Regex locations with URI in proxy_pass (invalid)
  • Variables in proxy_pass changing behaviour
  • Rewrite + proxy_pass combination

⚡ Quick fix

  1. Decide: pass-through (proxy_pass http://app;) or strip (location /api/ { proxy_pass http://app/; })
  2. Use rewrite ^/api/(.*)$ /$1 break; for explicit mapping
  3. Check the backend access log for the received path

Detailed fix by platform

Linux

  1. curl -v https://example.com/api/users and compare with the backend log line

How to diagnose

  1. Slash — proxy_pass trailing?
  2. Path — What backend sees?
  3. 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:

Where this error sits

Origin: Edge & web server. Errors that are often confused with or caused by this one (click to open):

1019 — Cloudflare Error 1019: Compute server error (Workers) (Cloudflare)1019404 — HTTP 404 Not Found (HTTP)404405 — HTTP 405 Method Not Allowed (HTTP)405connect() failed (111: Connection refused) while connecting to upstream — Nginx: [error] connect() failed (111: Connection refused) while connecting to upstream, upstream: "http://127.0.0.1:3000/" (Nginx / Apache)connect() failed (111…default backend - 404 — Ingress returns "404 Not Found" / "default backend - 404" (ingress-nginx) (Kubernetes)default backend - 404Network is unreachable — connect: Network is unreachable (ENETUNREACH) (Linux)Network is unreachableno resolver defined to resolve example.com — Nginx: [error] no resolver defined to resolve api.example.com, client: 203.0.113.5 (502 when proxy_pass uses a variable) (Nginx / Apache)no resolver defined t…path-to-regexp — TypeError: Missing parameter name at 1 (path-to-regexp) (Node.js)path-to-regexpproxy_pas…

Explore the map of this error Full error map →

🧠 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.