0

I have a two part question

Question 1

Is it wrong to use Apache as a proxy to my nodeJS server as it cannot handle Websockets. I am using Apache with BOSH presently and I would like to know what is the right way to deploy with node so that I can use websockets too.

My apache configurations are as follows



   ServerName example.com
   ProxyPass / http://localhost:9000/
   ProxyPassReverse /  http//localhost:9000/
  
        Order allow,deny
        Allow from all
  


Is this approach completely wrong? I am able to use my app (which works as an API ) without trouble. I would need to add websocket support soon and would this configuration fail then?

Question 2
I would also like to know how can I get NodeJS to write the logs to a file.

3 Answers 3

2

1) It is wrong to use something like Apache to proxy Node.js, it's better to use something like Nginx or Node solutions like node-proxy or bouncy. It's wrong because Apache is blocking and creates a new thread per connection, totally different from Nginx and Node. By using Apache you'll remove the advantages Node.js provides you (thousands concurrent connections and low memory footprint).

2) As far as I know, probably the most 'popular' logging library is Winston.

Sign up to request clarification or add additional context in comments.

4 Comments

What is the recommended solutions Nginx or node-http-proxy recommended by alFReD NSH which seems a lot like what I need. I can't find much information about why one would be better than the other.
Nginx is actually a web server that has "plugins" / "modules" (for gzipping, GeoIP, proxy-ing etc etc), while node-http-proxy is just a proxy built with Node.js. You can use either Nginx (usually people use it with additional modules, custom for their needs) or just node-http-proxy. Whichever you choose is good.
You're answer seems pretty familiar to mine! Why my answer didn't get accepted? :P
I liked the explanation on why Nginx is preferred over Apache. Apart from the that both answers were very informative and I really appreciate it. Thank you.
2

Well actually the mad scientists made node-http-proxy to make sure people don't use Apache or Nginx as a proxy for NodeJS. If you ask me I would say use the module, much easier and lighter and faster(not so sure, but it node!).

As of logging I would recommend using Winston module which is pretty easy to use.

Comments

1

With new version of Apache (2.4.5+), you may use mod_proxy_wstunnel to achieve this.

I recently did a simple experiment. It appears to work fine with the combination of Apache, Nodejs and socket.io.

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so

ProxyPass /socket.io/1/websocket/ ws://127.0.0.1:8899/socket.io/1/websocket/
ProxyPass /socket.io/ http://127.0.0.1:8899/socket.io/

Details: https://github.com/mksamfolk/sandbox/tree/master/apache_websocket

Comments

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.