-2

Now, I had patched nginx with the nginx_tcp_proxy_module, and it is running OK on port 8080.

How do I connect the clients to port 80 of nignx, not port 8080 of Node.js, so that having the nginx forward the request to Node.js?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
benyu
  • 11
  • 5
  • possible duplicate of [Nginx + (nodejs, socketio, express) + php site](http://stackoverflow.com/questions/14685924/nginx-nodejs-socketio-express-php-site) – Rajesh Ujade Sep 08 '14 at 06:08

1 Answers1

2

Just change 8080 to 80. But TCP and HTTP on the same port is not possible.

Aleternative solution:

  • Use HAProxy on port 80
  • Set up nginx to listen on port 81
  • Run your node.js app on port 8080
  • Configure HAProxy to
    • forward Host: your.nodejs.socketio.com to 127.0.0.1:8080
    • forward everything else to 127.0.0.1:81

If you go down this route you will probably want to preserve client IPs:

  • Configure HAproxy
  • Use RealIP module in nginx
  • Use X-Forwarded-For in socket.io

    socketio.handshakeData = function(data) {
        var d = socketio.Manager.prototype.handshakeData(data);
        d.ip = data.request.headers['x-forwarded-for'] || data.request.connection.remoteAddress;
        return d;
    };
    
Community
  • 1
  • 1
mak
  • 13,267
  • 5
  • 41
  • 47
  • Thanks, now haproxy had successfully forwarded http request to nginx and websocket requests to nodejs(only in chrome), but fail to forward xhr-polling and jsonp-polling requests( ie and firefox) – benyu Aug 21 '11 at 13:09
  • Remove `acl is_websocket hdr(Upgrade) -i WebSocket` – mak Aug 21 '11 at 13:14
  • Thanks for this answer. Saved me soo much time :-) – Mike Neumegen Mar 20 '12 at 07:24