Deploying NodeJS with Apache Proxy on Ec2 (Wrong?)

2019-08-24 01:07发布

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条回答
够拽才男人
2楼-- · 2019-08-24 01:31

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.

查看更多
等我变得足够好
3楼-- · 2019-08-24 01:35

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

查看更多
对你真心纯属浪费
4楼-- · 2019-08-24 01:47

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.

查看更多
登录 后发表回答