title: Nginx 502 Bad Gateway error when call api
body: <p>I have a Angular build and an Django backend providing API's running on one server. I've configured them in nginx with the frontend having a proxy to the backend server.</p>
  
  <p>The backend is running on the url 127.0.0.1:8000/api and the frontend is running on localhost</p>
  
  <p>Config:</p>
  
  <pre><code>worker_processes  1;
  
  events {
      worker_connections  1024;
  }
  
  http {
      server {
          listen 80;
          charset utf-8;
          server_name  localhost;
  
          root   /usr/share/nginx/html;
          index  index.html index.htm;
          include /etc/nginx/mime.types;
  
          gzip on;
          gzip_types text/css text/javascript application/x-javascript application/json;
  
          location /api {
              proxy_pass http://127.0.0.1:8000/api;
          }
  
          location / {
              try_files $uri $uri/ /index.html;
          }
      }
  }
  </code></pre>
  
  <p>Now when I do any api call from the frontend I get the a 502 Bad Gateway error</p>
  
  <blockquote>
    <p>GET <a href="http://localhost/api/posts/post/management" rel="nofollow noreferrer">http://localhost/api/posts/post/management</a> 502 (Bad Gateway)</p>
  </blockquote>