NGINX location directive proxy_pass not reaching backend server

I am trying to route to a backend server using Nginx proxy through docker and backend services are running in docker container locally. Root location / is getting routed whereas the location with /api/ is not getting routed.

Expected to be routed to

      location / {

    location /api/ { 
        rewrite ^/api/?(.*)$ /$1 break;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        add_header X-Content-Type-Options 'nosniff';
        add_header Cache-Control 'no-store, no-cache, must-revalidate, proxy- 
        revalidate, max-age=0';
        server_tokens off;
        return 200 'hello end GREET NGINX3' ;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        return 200 'hello end GREET NGINX3' ;