Skip to content

Serve an app under a sub-path with an nginx reverse proxy (strip the prefix) — by Jens Bradler on Server Fault

advancedforumCC BY-SA (Stack Exchange; version depends on post date)

To publish a backend at /foo/ without redirecting the browser, use a transparent rewrite inside the location block (rewrite ... break) and then proxy_pass. A 301/302 redirect would send visitors to an internal address they can't reach. The answer also suggests testing with curl -i.

Quick steps

  1. location /foo { rewrite /foo/(.*) /$1 break; proxy_pass http://backend; proxy_redirect off; proxy_set_header Host $host; }

Paraphrased from the source. Menus can differ by version, so check the original for full details.

Read the full thread on serverfault.com

Source: Serve an app under a sub-path with an nginx reverse proxy (strip the prefix) by Jens Bradler on Server Fault. Licence: CC BY-SA (Stack Exchange; version depends on post date).

Source reviewed
2026-11-02
Link checked
Not yet
Tested hands-on
Not by Oddbyte.Me

nginxreverse proxyrewriteproxy_pass

More in Community Answers (Stack Exchange)