Docker-compose network and nginx docker image proxy_pass issues

I am using the nginx image on docker hub. My default.conf is below:

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    location /api/ {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://api:4435/;
        proxy_set_header Host $host;
    }

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

‘api’ is the name of another one of my services which is up and running. The request doesn’t hit the api at all. Error message from nginx is below:

client_1  | 172.18.0.1 - - [23/Jul/2020:02:21:24 +0000] "POST /api/login HTTP/1.1" 404 145 "http://localhost/course/5ebc9e10f8144bff47de9cc8" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36" "-"
client_1  | 172.18.0.1 - - [23/Jul/2020:02:21:24 +0000] "POST /api/cards/search HTTP/1.1" 404 152 "http://localhost/course/5ebc9e10f8144bff47de9cc8" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36" "-"
client_1  | 172.18.0.1 - - [23/Jul/2020:02:21:24 +0000] "GET /api/course/5ebc9e10f8144bff47de9cc8 HTTP/1.1" 404 170 "http://localhost/course/5ebc9e10f8144bff47de9cc8" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36" "-"

I’ll include my Dockerfile as well for reference:

FROM nginx

RUN rm /etc/nginx/conf.d/default.conf

COPY build /usr/share/nginx/html

COPY default.local.conf /etc/nginx/conf.d/default.conf

EXPOSE 80 443

I have been searching for a solution for days, so any help would be much appreciated!