What are the advantages of having nginx or another web-server running as a reverse-proxy in front of the Node.JS? What does it provide?
在Node.JS前面使用nginx或其他web服务器作为反向代理运行的优点是什么?它提供什么?
(This question is intended for matters concerning web-apps, not web-pages).
(这个问题是关于网络应用而不是网页的。)
Thank you.
谢谢你!
2 个解决方案
#1
33
I think the greatest benefit is that you're then able to use the same port (80) for multiple applications. Otherwise, you'd need a new IP address for each nodejs application you have. Depending on how you set things up, you can also configure different folders and subdomains to different nodejs apps running on different ports. If you're building something big or complex, this is pretty great. Imagine being able to run your APIs on one node application, your website from another, and the logged-in website (member's area, dashboard, etc.) in another app. Your load balancer can determine who needs to go where (example.com/api* -> api.js, example.com/dashboard* -> dashboard.js, example.com -> app.js). This is not only useful for scaling, but also when things break, not everything breaks at once.
我认为最大的好处是您可以对多个应用程序使用相同的端口(80)。否则,您将需要为您拥有的每个nodejs应用程序提供一个新的IP地址。根据设置的方式,还可以为运行在不同端口上的不同nodejs应用程序配置不同的文件夹和子域。如果你正在构建一个大的或复杂的东西,这是非常棒的。想象一下,你可以在一个节点应用程序上运行api,在另一个节点应用程序上运行你的网站,在另一个应用程序中运行登录网站(成员的区域、仪表板等)。js,example.com/dashboard * - >仪表板。js,example.com - > app.js)。这不仅对缩放很有用,而且当物体断裂时,不是所有的东西都同时断裂。
To the maturity thing, meh. Nodejs + forever + node-http-proxy = Amazing. Run 1 proxy server for all of your apps with a minimal config/complexity (lower chance of failure). Then have fun with everything else. Don't forget to firewall off your internal ports, though ;)
.
对于成熟的东西,嗯。Nodejs + forever + node-http-proxy =惊人。为所有应用程序运行1个代理服务器,配置/复杂性最小(降低失败的几率)。然后尽情享受其他一切。不过,不要忘记防火墙关闭内部端口;)。
Some people make note of load balancing, which true, is a benefit. However, load balancing isn't something that most people will benefit from, since a single threaded, non-blocking nodejs thread can handle quite impressively large loads. I truly wouldn't even consider this as a difference if I were you. Load balancing is easy enough to implement when you need it, but otherwise utterly useless until you do.
有些人注意到负载平衡,这是一个好处。但是,负载平衡并不是大多数人都会受益的,因为单线程、非阻塞的nodejs线程可以处理非常大的负载。如果我是你,我真的不会认为这有什么不同。负载平衡在需要时很容易实现,但在需要时就完全没用了。
Also note, if you do go with a non-node proxy solution (nginx, tornado, etc.), just be sure NOT to use one that blocks. Apache blocks. Nginx doesn't. You don't want to throw away one of the greatest benefits of using nodejs in the first place on a crummy server.
还要注意,如果使用非节点代理解决方案(nginx、tornado等),一定不要使用阻塞的解决方案。Apache模块。Nginx没有。您不希望在糟糕的服务器上首先使用nodejs的最大好处之一被抛弃。
#2
9
Having a more mature software as proxy is better for security and reliability. Nginx, Apache and others have been tested against a multitude of cases and used in production for years.
拥有一个更成熟的软件作为代理更有利于安全性和可靠性。Nginx、Apache等公司已经针对大量案例进行了测试,并在生产中使用了多年。
You can also use features from these web server that otherwise you would have to implement yourself or use a node.js module. Like caching, statistics, balancing, etc.
您还可以使用这些web服务器的特性,否则您将不得不自己实现或使用节点。js模块。比如缓存、统计、平衡等等。
On the other side you would lose some features from node.js, realtime features like websockets (on port 80, you can still use other ports), page buffering and depending on the reverse proxy used, control over your caching and headers.
在另一方面,您将会从node失去一些特性。js,实时特性,如websockets(在端口80上,你仍然可以使用其他端口),页面缓冲,根据使用的反向代理,控制你的缓存和标题。
Edit:
编辑:
- NginX now supports websocket proxying and possibly others.
- NginX现在支持websocket代理,也可能支持其他功能。
- Apache has a module to proxy websockets.
- Apache有一个代理websockets的模块。
#1
33
I think the greatest benefit is that you're then able to use the same port (80) for multiple applications. Otherwise, you'd need a new IP address for each nodejs application you have. Depending on how you set things up, you can also configure different folders and subdomains to different nodejs apps running on different ports. If you're building something big or complex, this is pretty great. Imagine being able to run your APIs on one node application, your website from another, and the logged-in website (member's area, dashboard, etc.) in another app. Your load balancer can determine who needs to go where (example.com/api* -> api.js, example.com/dashboard* -> dashboard.js, example.com -> app.js). This is not only useful for scaling, but also when things break, not everything breaks at once.
我认为最大的好处是您可以对多个应用程序使用相同的端口(80)。否则,您将需要为您拥有的每个nodejs应用程序提供一个新的IP地址。根据设置的方式,还可以为运行在不同端口上的不同nodejs应用程序配置不同的文件夹和子域。如果你正在构建一个大的或复杂的东西,这是非常棒的。想象一下,你可以在一个节点应用程序上运行api,在另一个节点应用程序上运行你的网站,在另一个应用程序中运行登录网站(成员的区域、仪表板等)。js,example.com/dashboard * - >仪表板。js,example.com - > app.js)。这不仅对缩放很有用,而且当物体断裂时,不是所有的东西都同时断裂。
To the maturity thing, meh. Nodejs + forever + node-http-proxy = Amazing. Run 1 proxy server for all of your apps with a minimal config/complexity (lower chance of failure). Then have fun with everything else. Don't forget to firewall off your internal ports, though ;)
.
对于成熟的东西,嗯。Nodejs + forever + node-http-proxy =惊人。为所有应用程序运行1个代理服务器,配置/复杂性最小(降低失败的几率)。然后尽情享受其他一切。不过,不要忘记防火墙关闭内部端口;)。
Some people make note of load balancing, which true, is a benefit. However, load balancing isn't something that most people will benefit from, since a single threaded, non-blocking nodejs thread can handle quite impressively large loads. I truly wouldn't even consider this as a difference if I were you. Load balancing is easy enough to implement when you need it, but otherwise utterly useless until you do.
有些人注意到负载平衡,这是一个好处。但是,负载平衡并不是大多数人都会受益的,因为单线程、非阻塞的nodejs线程可以处理非常大的负载。如果我是你,我真的不会认为这有什么不同。负载平衡在需要时很容易实现,但在需要时就完全没用了。
Also note, if you do go with a non-node proxy solution (nginx, tornado, etc.), just be sure NOT to use one that blocks. Apache blocks. Nginx doesn't. You don't want to throw away one of the greatest benefits of using nodejs in the first place on a crummy server.
还要注意,如果使用非节点代理解决方案(nginx、tornado等),一定不要使用阻塞的解决方案。Apache模块。Nginx没有。您不希望在糟糕的服务器上首先使用nodejs的最大好处之一被抛弃。
#2
9
Having a more mature software as proxy is better for security and reliability. Nginx, Apache and others have been tested against a multitude of cases and used in production for years.
拥有一个更成熟的软件作为代理更有利于安全性和可靠性。Nginx、Apache等公司已经针对大量案例进行了测试,并在生产中使用了多年。
You can also use features from these web server that otherwise you would have to implement yourself or use a node.js module. Like caching, statistics, balancing, etc.
您还可以使用这些web服务器的特性,否则您将不得不自己实现或使用节点。js模块。比如缓存、统计、平衡等等。
On the other side you would lose some features from node.js, realtime features like websockets (on port 80, you can still use other ports), page buffering and depending on the reverse proxy used, control over your caching and headers.
在另一方面,您将会从node失去一些特性。js,实时特性,如websockets(在端口80上,你仍然可以使用其他端口),页面缓冲,根据使用的反向代理,控制你的缓存和标题。
Edit:
编辑:
- NginX now supports websocket proxying and possibly others.
- NginX现在支持websocket代理,也可能支持其他功能。
- Apache has a module to proxy websockets.
- Apache有一个代理websockets的模块。