title: Frontend to backend requests (react, nodejs) do not go through nginx. How can I make nginx intercept the traffic?
body: <p>I have a nodejs server listening on port 2000 and a react development server listening on port 4000.</p>
  <p>In my config file for nginx, I realized that I can never create location blocks for a location beginning with &quot;/api/&quot; (basically all my requests) because network requests from the frontend to the backend aren't accepted through nginx (I thought they were).</p>
  <p>I'm not sure how to make nginx intercept requests. I was fooled because the loadbalancing (for the frontend only as I now see) seemed to work.</p>
  <p>Accesses to any page would be split among the servers, BUT the frontend to backend requests are not going through nginx for reasons I do not understand.</p>
  <p>In the configuration file for nginx (not nginx.conf) below, the only location block that &quot;works&quot; is
  the first (location /).</p>
  <p>In other words, it's as if the blocks beginning with /api/ do not exist because nginx does not seem to be handling backend requests at any point.</p>
  <p>I want to have backend requests go through nginx, so I can create location blocks from /api/ and implement things like rate limiting.</p>
  <p>Please, I am very lost and have spent countless hours trying to figure this out. I could really use some guidance and answers!</p>
  <pre><code>limit_req_zone $binary_remote_addr zone=zonenot:15m rate=1r/m;
  
  
  log_format upstreamlog '$server_name to: $upstream_addr [$request] '
      'upstream_response_time $upstream_response_time '
      'msec $msec request_time $request_time'
      '$status $body_bytes_sent &quot;$http_referer&quot;'
      '&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;';
      
  
  upstream lbfrontend {
      least_conn;
      # frontendservers
  
      server xxx.xxx.xxx:4000;
      server kkk.kkk.kkk:4000;
  
      
  }
  
  upstream lbbackend {
      least_conn;
  
      # backendservers
      server xxx.xxx.xxx:2000;
      server kkk.kkk.kkk:2000;
  
  }
  
      
      
      server {
  
          listen 80;
          server_name xxx.xxx.xxx;
  
          access_log /var/log/nginx/access.log upstreamlog;
  
          location / {
              proxy_pass http://lbfrontend;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection &quot;Upgrade&quot;;
              proxy_set_header Host $host;
          }
  
          location /api/notification/getnotifications {
  
              limit_req zone=zonenot;
  
              proxy_pass http://lbbackend;
  
              
  
          }
          location ^~ /api/ {
  
              proxy_pass http://lbbackend;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection &quot;Upgrade&quot;;
              proxy_set_header Host $host;
              
          }
  
  
  
          
      }
  </code></pre>