# Nginx: reverse proxy returns 404 — location /api/ { proxy_pass http://app:3000/; } strips the prefix (or keeps it)

**Code:** `proxy_pass with a URI changes the path (404 from upstream)` · **Category:** Nginx / Apache · **Seen on:** Nginx, Linux

Whether `proxy_pass` has a URI part decides if the matched prefix is stripped, so the backend receives an unexpected path.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/nginx-apache/nginx-proxy-pass-uri-path-404)
