What are the advantages/disadvantages of using node.js with a connect.vhost directive as a router rather than NGINX using proxy_pass?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Connect.vhost
pros
- fairly simple
- only one server to worry about
- you won't have multiple processes on the same host fighting for the same memory
cons
- does not scale beyond 1 core, if you need to cluster beyond one machine, you are back with nginx or similar anyway.
- you still need a solution to redirect port 80 to node.js (unless you are fine running node as root), such as iptables, or nginx.
nginx
pros
- this is used by thousands (millions?) of websites as their front-end or only server
- won't add much overhead
- you could serve static files directly without having node.js do it
I'd pick nginx pretty much by default, but I could see using Connect.vhost for something I need quick and won't need to scale on.
回答2:
Connect vhost Advantage: WebSockets just work. You don't have to install and configure nginx. The whole stack is node.js. Behavior may be more customizable to your liking.
Nginx Advantage: Nginx is a mature and stable web server. It's very unlikely to crash or exhibit strange behavior. It can also host your static resources, PHP site, etc.
If it were me, unless I needed some particular feature of Nginx, I'd pick Connect vhost or node-http-proxy for the sake of having an all-node.js stack.