title: How to Load balance containers using nginx
body: <p>I aim to have 2 backend containers and an nginx container that will act as a loadbalancer.</p>
  <p>This is my <code>compose file</code>:</p>
  <pre><code>version: '3.3'
  
  services:
      api_backend:
          container_name: api_backend
          hostname: api_backend
          build: ./api_backend_server/
          restart: always
          networks:
            - routing_net
  
      cdn_backend:
          container_name: cdn_backend
          hostname: cdn_backend
          build: ./cdn_server/
          restart: always 
          networks:
            - routing_net
      
      nginx:
          depends_on:
            - api_backend
            - cdn_backend
          build: ./externalNginx/
          ports:
            - 80:80
            - 443:443
          restart: always
          networks:
            - routing_net
            
  networks:
    routing_net:
  </code></pre>
  <p>This is my <code>nginx.conf</code>:</p>
  <pre><code>events { worker_connections 1024; }
  
  http {
      # List of application servers
      upstream api_servers {
          server cdn_nginx;
      }
  
      # Configuration for the server
      server {
  
          # Running port
          listen 80;
  
          # Proxying the connections
          location / {
          #return 200 'hello';
              proxy_pass         http://api_servers/;
          }
      }
  }
  </code></pre>
  <p>When I run this I get:</p>
  <pre><code>nginx_1        | 2022/01/31 16:54:03 [emerg] 1#1: host not found in upstream &quot;cdn_nginx&quot; in /usr/local/openresty/nginx/conf/nginx.conf:6
  
  </code></pre>
  <p>When I enter the nginx and run :</p>
  <pre><code>ping cdn_nginx
  </code></pre>
  <p>It works (I get the currect IP adress, what do I do wrong?</p>