title: socket connect_error : [Error: xhr poll error] with server behind nginx reverse proxy
body: <p>My React Native 0.66 app uses <code>socket.io-client 4.4.1</code> to connect with nodejs <code>socket.io 4.4.3</code> server. Here is the socket client code at in app:</p>
  <pre><code>import { io } from &quot;socket.io-client&quot;;
  let socUrl = 'https://mydomain.top'; //&lt;&lt;==domain name for the nodejs server 
  let _socket = io(socUrl, {. //&lt;&lt;==option to establish socket to nodejs 14.x server
    path:'/sokt',
  });  
  
  _socket.on(&quot;connect&quot;, () =&gt; {
    console.log(&quot;socket.id in chat : &quot;, _socket.id); //&lt;&lt;== never fired because no connection
  });
  _socket.on(&quot;connect_error&quot;, (err)=&gt;{
    console.log(&quot;socket connect_error : &quot;, err) //&lt;&lt;==[Error: xhr poll error]
  })
  </code></pre>
  <p>Tried other option in establishing socket such as <code>secure:true, rejectUnauthorized:false</code> and the error is the same or error of <code>timeout</code>.</p>
  <p>The socket on server side is:</p>
  <pre><code>const express = require('express');
  const app = express();
  const httpServer = require('http').createServer(app);
  const {Server} = require(&quot;socket.io&quot;);  //socket.io ver 4.4.3
  const io = new Server(httpServer, {
    cors: {
      origin: &quot;https://mydomain.top&quot; //&lt;&lt;==domain name for the nodejs server
    }
  });
  ....
  httpServer.listen(port, () =&gt; console.log(`Listening on port ${port}`)); 
  </code></pre>
  <p>The nodejs server is behind nginx reverse proxy and proxy-pass seems working fine. Here is the config of nginx reverse proxy:</p>
  <pre><code>location ~ ^/(sokt|socket.io) {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $host;
  
        proxy_pass http://127.0.0.1:5000;
  
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection &quot;upgrade&quot;;
    }
  </code></pre>
  <p>UPDATE: here is the nginx access log entry of connect request from React Native front end:</p>
  <pre><code>xx.xx.92.84 - - [19/Feb/2022:00:24:48 +0800] &quot;GET /sokt/?EIO=4&amp;transport=polling&amp;t=NyDfdOt HTTP/1.1&quot; 404 144 &quot;-&quot; &quot;okhttp/4.9.1&quot; &quot;-&quot;&quot;127.0.0.1:5000&quot; &quot;127.0.0.1:5000&quot;&quot;-&quot; &quot;http_authorization&quot;
  </code></pre>
  <p>UPADTE1: output from curl remotely:</p>
  <pre><code>curl &quot;https://mydomain.top/socket.io/?EIO=4&amp;transport=polling&quot;
  0{&quot;sid&quot;:&quot;8wYqHl9Lc_rLCnksAAAA&quot;,&quot;upgrades&quot;:[&quot;websocket&quot;],&quot;pingInterval&quot;:25000,&quot;pingTimeout&quot;:20000}% 
  
           
  </code></pre>