fix(nginx): proxy every /api/ URL instead of serving it as a static file

nginx picks a regex location over a plain prefix location, so with
`location /api/` the static-asset rule (\.png$ …) won any API request whose
path ended in an image extension: /api/img/<hash>.png?w=400 was looked up
under /usr/share/nginx/html and 404ed instead of reaching the API. The same
file at /uploads/<hash>.png still loaded, which is exactly why an uploaded
card thumbnail showed broken on the server but opened fine at full size —
and why only .png/.jpg/.gif/.svg uploads were affected while .webp ones
looked fine.

^~ stops the regex pass. Verified in an nginx:alpine container with this
config: /api/img/abc.png?w=400 now reaches the proxy (502 without an
upstream) instead of 404, while bundled assets still come from disk.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
mahmood
2026-11-26 14:28:15 +03:30
co-authored by Claude Haiku 5.5
parent 7db264ce92
commit e79afddd76
3 changed files with 22 additions and 3 deletions
+4 -1
View File
@@ -9,7 +9,10 @@ server {
# any real photo with a bare 413 before the request ever reached it.
client_max_body_size 20m;
location /api/ {
# ^~ keeps the static-asset regex below from swallowing API URLs that end
# in .png/.jpg/.svg (e.g. /api/img/<hash>.png?w=400), which nginx would
# otherwise look up on disk and 404 instead of proxying.
location ^~ /api/ {
proxy_pass http://api:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;