brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: a trailing slash on nginx proxy_pass changes the path the backend sees

Nginx
~/tips/tip-nginx-proxy-pass-trailing-slash

location /app/ { proxy_pass http://127.0.0.1:3000; } # backend sees /app/page

Shows how the slash at the end of proxy_pass strips or keeps the location prefix.

One character decides whether the backend gets /app/page or /page.

location /app/ { proxy_pass http://127.0.0.1:3000;  }   # backend sees /app/page
location /app/ { proxy_pass http://127.0.0.1:3000/; }   # backend sees /page

When proxy_pass has no URI part, nginx passes the original request path unchanged. When it has one, even a bare /, the part of the path that matched the location is replaced by it. That is the standard way to mount an app under a subpath. The rule is different inside regex locations, where a URI part is not allowed at all, and when variables are used in proxy_pass. Check what the backend receives by watching its access log while you request /app/page once with each variant, and reload nginx between the two tests.

Further reading: ngx_http_proxy_module: proxy_pass

Going deeper: Guide: fix a 502 Bad Gateway in Nginx Proxy Manager, with a checklist that finds the cause

More Nginx tips sudo certbot --nginx -d example.com -d www.example.com /data/nginx/custom/server_redirect.conf map $http_upgrade $connection_upgrade { proxy_intercept_errors on; proxy_redirect http://localhost:3000/ /app/; All Nginx tips (50) All topics

Link