0

After reading several articles, I'm still unable to get my socket.io communication working via a nginx proxy.

Below is my nginx configuration:

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

location ~* \.io {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
}

Here's how my node.js express server is wired up:

const express = require('express');
const app = express();
const http = require('http').Server(app);
const io = require('socket.io')(http);

Everything seems to work fine on my local dev machine ie. I'm seeing my onConnection log message and all communication works well too.

On production howsoever, my browser gets all valid responses but I'm not seeing any onConnection logs and communication over the socket isn't working.

Chrome network tab requests (click to open image in full size)

Chrome network tab requests

alexander.polomodov
  • 1,060
  • 3
  • 10
  • 14

1 Answers1

0

It could be that port 3000 is blocked by a firewall on your production server. You can check if it’s open by running the following command from your local dev machine

telnet <ip-address-of-your-production-server> 3000

This will try to open a connection to port 3000 on the production server. If you get a time out or deny, the port is not open.

redoc
  • 33
  • 1
  • 1
  • 5
  • That's not the problem. As you can tell from my screenshot and description, requests are receiving a 200 OK response. It's just that the websocket data isn't going through. I was able to solve this by eliminating nginx and talking directly to a node.js http-proxy listening on 3001 but that defeats the purpose of this question. – Anshul Koka Aug 27 '18 at 17:53