title: Why do I keep getting 404 error for Socket.io polling requests?
body: <p>Getting quite a few of these spawning from my React app: <code>GET http://exampleenvv2-env.eba-yjtafbmz.us-east-1.elasticbeanstalk.com/socket.io/?EIO=3&amp;transport=polling&amp;t=NLE1Pn5</code></p>
  <p>My React sits on port 8080 and Express on 5000, both behind Nginx on AWS Beanstalk. From SSH'ing into the instance, it appears both are running fine, and since I can access the React app in browser fine, it looks like it properly routes to that server.</p>
  <p>I was able to get a basic chat app working locally between two browser windows.</p>
  <p>I do this in my React page.js:</p>
  <pre><code>import socketIOClient from &quot;socket.io-client&quot;;
  var io = require('socket.io');
  var socket = socketIOClient();
  </code></pre>
  <p>Server.js (for Express/Socket.io listening):</p>
  <pre><code>const express = require('express');
  const app = express();
  const http = require('http').Server(app);
  const io = require('socket.io')(http);
  const router = express.Router();
  
  var Immutable = require('immutable');
  var SortedSet = require(&quot;collections/sorted-set&quot;);
  
  var Map = Immutable.Map;
  var List = Immutable.List;
  
  var hostname = process.env.IP || 'localhost';
  var port = 5000;
  
  var games = Map();
  var players = Map();
  var availableKeys = SortedSet();
  var maxKey = 0;
  
  /.../
  
  http.listen(port, hostname, function () {
  console.log(&quot;Server is listening on http://&quot; + hostname + &quot;:&quot; + port);
  });
  </code></pre>
  <p>Nginx location config portion:</p>
  <pre><code>location / {
    proxy_http_version  1.1;
    proxy_pass          http://127.0.0.1:8080/;
    proxy_set_header    Host $host;
    proxy_set_header    X-Real-IP $remote_addr;
    proxy_set_header    Connection $connection_upgrade;
    proxy_set_header    Upgrade $http_upgrade;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
  }
  
  location /socket.io {
    proxy_pass                http://127.0.0.1:5000/;
    proxy_set_header          Host $host;
    proxy_set_header          X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header          X-NginX-Proxy true;
    proxy_set_header          X-Real-IP $remote_addr;
    proxy_ssl_session_reuse   off;
    proxy_cache_bypass        $http_upgrade;
  }
  </code></pre>
  <p>I've tried using the path option to '/socket.io' for node and react, that didn't seem to help.</p>
  <p>Here's an example of the <code>error.log</code>:</p>
  <pre><code>2020/10/22 01:36:44 [error] 20352#0: *279 connect() failed (111: Connection refused) while connecting
  to upstream, client: 172.31.22.103, server: , request: &quot;GET /socket.io/
  EIO=3&amp;transport=polling&amp;t=NLDyuCl HTTP/1.1&quot;, upstream: &quot;http://127.0.0.1:5000//? 
  EIO=3&amp;transport=polling&amp;t=NLDyuCl&quot;, host: &quot;exampleenvv2-env.eba-yjtafbmz.us-east- 
  1.elasticbeanstalk.com&quot;, referrer: &quot;http://exampleenvv2-env.eba-yjtafbmz.us-east- 
  1.elasticbeanstalk.com/&quot;
  </code></pre>