title: Nginx simple proxy doesn't work in Docker
body: <p>I've a backend and a frontend that run in two containers in Docker, and both are accessible from my browser with their ports:</p>
  
  <pre><code>localhost:8081 # frontend
  localhost:8082 # backend
  </code></pre>
  
  <p>Now, I want to use an Nginx server that receives all the traffic (port 80) and redirects:</p>
  
  <pre><code>localhost -&gt; to frontend
  localhost/api -&gt; to the backend
  </code></pre>
  
  <p>After trying almost everything in <code>nginx.conf</code> file (nothing worked), I found in an SO Question that the file I must modify is:</p>
  
  <blockquote>
    <p>/etc/nginx/sites-enabled/default</p>
  </blockquote>
  
  <p>So I try to modify it, and now nginx runs. And with runs, I mean that at least when I access <code>localhost</code>, nginx welcome page is shown. However, I still can't make my nginx route traffic (proxy way, not redirect).</p>
  
  <p>Right now my <code>docker-compose</code> file has the following look (snippet for nginx plus those two services):</p>
  
  <pre><code>  nginx:
      image: nginx:latest
      ports:
        - 80:80
      volumes:
        - ./Dockerfiles/nginx/default:/etc/nginx/sites-enabled/default
      links:
        - frontend
        - backend
      depends_on:
        - frontend
        - backend
    frontend:
      build: ./Dockerfiles/frontend
      volumes:
        - ./Dockerfiles/frontend/www/src:/usr/src/app
        - ./logs/frontend/httpd:/var/logs/httpd
      ports:
        - "8081:3000"
      links:
        - backend
    backend:
      build: ./Dockerfiles/backend
      volumes:
        - ./Dockerfiles/backend/www:/var/www/html
        - ./logs/backend/httpd:/var/logs/httpd
      ports:
        - "8082:80"
      links:
        - "database"
        - "redis"
      depends_on:
        - database
        - redis
  </code></pre>
  
  <p>My <code>default</code> file as said before, for nginx config is:</p>
  
  <pre><code>server {
          listen 80 default_server;
  
          # Add index.php to the list if you are using PHP
          index index.html index.htm index.php index.nginx-debian.html;
  
          server_name _;
  
          location / {
                  # First attempt to serve request as file, then
                  # as directory, then fall back to displaying a 404.
                  #try_files $uri $uri/ =404;
              proxy_pass http://frontend:8081/;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection 'upgrade';
              proxy_set_header Host $host;
              proxy_cache_bypass $http_upgrade;
          }
  
          location /api {
              proxy_pass http://backend:8082/public/;
              proxy_http_version 1.1;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection 'upgrade';
              proxy_set_header Host $host;
              proxy_cache_bypass $http_upgrade;
          }
  
  }
  </code></pre>
  
  <p>And when I try to access my <code>/api</code> url for example, the error that nginx is telling my is:</p>
  
  <blockquote>
    <p>nginx_1     | 2018/12/17 21:44:09 [error] 6#6: *1 open() "/usr/share/nginx/html/api" failed (2: No such file or directory), client: 172.20.0.1, server: localhost, request: "GET /api HTTP/1.1", host: "localhost"</p>
  </blockquote>
  
  <p>Which seems like it's trying to retrieve a file from local filesystem (something that I can't understand, given the conf. files).</p>
  
  <p>Any lead, idea or tip?</p>