How to forward request to Node.js from nginx with tcp_proxy_module?
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 r开发者_运维百科equest to Node.js?
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
- forward
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; };
精彩评论