title: proxy socket io fails to connect with nginx, node on docker
body: <p>I struggle to connect a socket.io instance in my docker app using nginx, node and react. The socket requests remains pending and then fails after some time. I tried different config to make the socket request proxified by nginx for the node server but no success. It used to work outside docker but now things are completely stuck with my socket failing.</p>
  
  <p>Here is my actual nginx config :</p>
  
  <pre><code>upstream frontend {
      least_conn;
      server client:8080;
  }
  
  upstream backend {
      least_conn;
      server server:8080;
  }
  
  server {
      listen 80;
  
      server_name localhost;
  
      location / {
          proxy_pass http://frontend;
          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;
          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 /ws/ {
          proxy_pass http://backend;
          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>Here my docker compose file</p>
  
  <pre><code>version: '3'
     services:
  
       nginx:
         build:
           context: ../..
           dockerfile: ./dev-kit/docker/nginx/Dockerfile
         ports:
           - 8080:80
         links:
           - client
           - server
  
    client:
      build: ../../client
      ports:
        - 8088:8080
      volumes:
        - ../../client:/app:cached
      command: npm run start
  
    server:
      build: ../../server
      ports:
        - "8082:8080"
      volumes:
        - ../../server:/app:cached
      depends_on:
        - "mongo"
  
    mongo:
      image: "mongo"
      volumes:
        - /usr/local/var/mongodb/:/data/db
      ports:
        - "27017:27017"
  </code></pre>
  
  <p>Here is the server side on express:</p>
  
  <pre><code>const express           = require('express');
  const app               = module.exports = express();
  const http              = require('http').Server(app);
  
  const bodyParser        = require('body-parser');
  const io                = require('socket.io')(http);
  
  const session           = require('express-session');
  const MongoStore        = require('connect-mongo')(session);
  
  const appInterface = process.env.HOST || '0.0.0.0';
  const port = process.env.PORT || 8080;
  
  app.use((req, res, next) =&gt; {
      res.header('Access-Control-Allow-Origin', '*');
      res.header('Access-Control-Allow-Headers', 'Origin, X-Requested- With, Content-Type, Accept, x-access-token');
      res.header('Access-Control-Allow-Methods', 'GET, PUT, POST, DELETE');
      next();
  });
  
  io.on('connection', (socket) =&gt; {
    console.log('one user connected !');
    socket.on('register', (userId) =&gt; {
      users[userId] = socket.id;
    });
  });
  
  // Start server
  http.listen(port, appInterface.toString(), function (err) { 
     console.log('[%s] Listening on http://localhost:%d', 
     app.settings.env, port); 
  });
  </code></pre>
  
  <p>This is never executed unfortunately because the socket io request fails.</p>
  
  <p>And finally, here my app.js on the client side where I instanciate a socket io instance :</p>
  
  <pre><code>const socket = io('http://server:8080', { path: '/ws/socket.io' });
  socket.emit('register', XXXX);
  </code></pre>
  
  <p>Your help would be really appreciated. I tried a lot of different nginx config to proxy the socket io request to the server but no success.</p>