-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?

1

1 Answer 1

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;
    };
    
Sign up to request clarification or add additional context in comments.

2 Comments

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)
Remove acl is_websocket hdr(Upgrade) -i WebSocket

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.