0

Can I use Apache as main web server, but have websocket connection through Apache proxy between node.js and client webpage? And how to set up this?

VAGrus
  • 73
  • 1
  • 1
  • 6

2 Answers2

0

Yes, and I would recommend this approach (full webserver in front, multiple node servers in back) for many reasons (speed, security, single SSL termination... etc).

Use mod_proxy for this, for example if you have your node service running on port 3000 on the same host as Apache and want it accessible from www.example.com/node then use this config:

ProxyPass /node/ http://localhost:3000/node ProxyPassReverse /node/ http://localhost:3000/node

See more details here: NodeJs instead of Apache

Community
  • 1
  • 1
Barry Pollard
  • 40,655
  • 7
  • 76
  • 92
0

I recently had a heated debate with a former colleague (notice, I said former) regarding web sockets and exactly what they are / how they work... He was confused in calling it an "HTTP Upgrade" and was dead-set on believing the web server serving the page had to also host the web socket. Currently, I am developing an open source web socket library called libwebsock... Right now, v1 is buggy and needs some work (it leaks memory and isn't as powerful as it soon will be with the second release, in regards to optimization) - but it's on its way to being done. That being said, I can give you some better insight to this...

What serves the page is irrelevant. You could use Apache, IIS, have some PHP in there and so forth. The web socket connection acts as a simple TCP connection, but uses HTTP headers to initiate the connection. My opinion, this was done to float it through firewalls and standardize it as an extension of HTTP, but by all means - it's still completely separate from HTTP.

Currently, I use nginx to serve my page, and I use a C written web socket server to service the web socket connections. While they may connect to www.mywebsocketsite.com on port 80, javascript is delivered that opens the web socket connection to port 8085 (hypothetical), which connects to said C written program. From there, JavaScript is used to send and process received data. The web socket itself is completely independent of the web server that serves the page to load it. Think of a web socket as nothing more than a streaming TCP connection that stays alive between the clients browser and your server, and your web server as the deliverance mechanism to get the instructions to the client.