使用 Node.js 代理 HTTP 请求的价值
我最近开始开发一款多人浏览器游戏,该游戏将使用 nowjs 从服务器状态同步玩家状态。我是服务器端开发的新手(我所说的很多事情可能都是错误的),虽然我了解 Node.js 本身如何工作,但我已经看到了有关通过另一种服务器技术代理 HTTP 请求的讨论( a la NGinx 或 Apache)以提高效率。
我不明白为什么这样做会有好处,尽管我已经看到了很多关于如何这样做的解释。我当前的计划是将游戏的网站和信息与游戏本身放在同一服务器上,因此如果代理节点有任何收益,我很想知道原因。
I have very recently started development on a multiplayer browser game that will use nowjs to synchronize player states from the server state. I am new to server-side development (so many of the things I'm saying are probably being said incorrectly), and while I understand how node.js works on its own I have seen discussions about proxying HTTP requests through another server technology (a la NGinx or Apache) for efficiency.
I don't understand why it would be beneficial to do so, even though I've seen plenty of explanations of how to do so. My current plan is to have the game's website and info on the same server as the game itself, so if there is any gain from proxying node I'd love to know why.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的问题的上下文中,您似乎正在寻找有关实施反向代理 在你的 Node.js Web 服务器前面。总之,反向代理(取决于实现)可以提供以下开箱即用的功能:
所有这些功能都是 横切关注点,您不需要在应用程序层/代码中容纳这些关注点。通过在代理中实现这些功能,您可以专注于为您的应用程序开发代码,并让 Web 服务器做它擅长的事情,为您的应用程序提供 HTTP 请求。
nginx 似乎是反向代理/节点配置中的常见选择,如果您看一下模块参考 您应该了解代理可以提供哪些功能。
In the context of your question it seems you are looking for an answer on the benefits of implementing a reverse proxy in front of your node.js webserver. In summary, a reverse proxy (depending on implementation) can provide the following features out of the box:
All these features are cross-cutting concerns that you should not need to accommodate in your application tier/code. By implementing these features within the proxy it allows you to focus on developing the code for your application and leaves the web server to do what it's good at, serving the HTTP requests for your application.
nginx appears to be a common choice in a reverse proxy/node configuration and if you take a look at the modules reference you should get a feel for what features the proxy can provide.
当您说“通过另一种技术”时,我假设您的意思是通过专用 Web 服务器,例如 NGinx 或 Apache。
您这样做的原因是在生产环境中,有许多考虑因素您不希望您的应用程序必须自己完成。缓存、域(或子域)映射,也许还有安全性、SSL、负载平衡和提供静态文件等等。
Web 服务器已经构建为可以为您执行所有这些操作,因此它们可以处理它们,然后仅将实际需要由您的应用程序处理的请求传递到您的应用程序。他们还针对这些事情进行了优化,并且可能会比普通开发人员做得更好,甚至更好。
希望有帮助。
When you say "through another technology" I assume you mean through a dedicated web server such as NGinx or Apache.
The reason you do that is b/c in a production environment there are a number of considerations you don't want your application to have to do on its own. Caching, domain (or sub-domain) mapping, perhaps security, SSL, load balancing, and serving static files to name a few.
The web servers are already built to do all those things for you, and so they can handle them and then pass only the requests on to your app that actually need to be handled by your app. They're also optimized for doing those things and will probably do them as well or better than the average developer can.
Hope that helps.
人们没有在这里添加的另一个问题是,使用前端代理,当您需要关闭服务进行维护(甚至只是重新启动它)时,nginx 可以提供一个漂亮的“YourCompanyName 目前正在维护”页面,带来更愉快的用户体验。
Another issue that people haven't added in here is that with a front-end proxy, when you need to take your service down for maintenance (or even just restart it), nginx can serve up a pretty "YourCompanyName is currently under maintenance" page, making for a much more pleasant user experience.