Nginx unexpected redirects (304)

Hi,

I’m having trouble with docker-compose and nginx. First, I have this docker-compose.yml:

services:
  nginx:
    build: ./nginx
    ports:
      - '8080:80'
    depends_on:
      - web
      - api
  
  web:
    build: ./web
    depends_on:
      - api
 
  api:
    build: ./api

Both web (port 3000) and api (port 8000) are express servers that return WEB and API respectively. Now, inside ./nginx:

# Dockefile

FROM nginx:alpine

COPY ["default.conf", "/etc/nginx/conf.d/"]

EXPOSE 80
# default.conf

server {
  location / {
    proxy_pass  http://web:3000;
  }

  location /api {
    proxy_pass  http://api:8000;
  }
}

Now, when I go to http://localhost:8080, I get WEB, but when I go to http://localhost:8080/api, it redirects to http://localhost:1337/api/ and I get nothing (by the way, it throws a 304 error)

However, when I write this default.conf (put api in /)

# default.conf

server {
  location / {
    proxy_pass  http://api:8000;
  }

  location /api {
    proxy_pass  http://web:3000;
  }
}

I get the same result but in / i get API, so both servers work.