node.js 将 AngularJS 应用程序部署到普通的 Apache HTTP 服务器是一种常见的选择吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22224312/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:58:29  来源:igfitidea点击:

Is it a common choice to deploy an AngularJS app to a vanilla Apache HTTP server?

node.jsangularjs

提问by JBT

I was curious about what kind of server an AngularJS app was usually deployed into, and Google didn't give a satisfactory answer. In particular, it looks to me that an AngularJS app is just a collection of static files, so is it common to just deploy such an app into a vanilla Apache HTTP server in production? Or is a light-weighted Node.js server preferred?

我很好奇AngularJS应用通常部署在什么样的服务器上,谷歌没有给出满意的答案。特别是,在我看来,AngularJS 应用程序只是静态文件的集合,那么在生产中将这样的应用程序部署到普通的 Apache HTTP 服务器中是否常见?还是首选轻量级 Node.js 服务器?

Thank you very much.

非常感谢。

回答by marni

I run nginx to serve static AngularJS content. The backend functionality is served by NodeJS server that provides all necessary dynamic content and answers REST requests from the client-side. Nginx routes the dynamic queries to NodeJS, and serves static content directly. Both, client-side and server-side logic is written in the same language (JavaScript, or CoffeeScript).

我运行 nginx 来提供静态 AngularJS 内容。后端功能由 NodeJS 服务器提供服务,它提供所有必要的动态内容并回答来自客户端的 REST 请求。Nginx 将动态查询路由到 NodeJS,并直接提供静态内容。客户端和服务器端逻辑都是用相同的语言(JavaScript 或 CoffeeScript)编写的。

The biggest benefit of this is that we can load-balance client-side static content and backend content separately. It depends on the size of your app and demands that it makes regarding the dynamic content access.

这样做的最大好处是我们可以分别对客户端静态内容和后端内容进行负载均衡。这取决于您的应用程序的大小以及它对动态内容访问的要求。

Some other posts on the subject of deploying AngularJS:

关于部署 AngularJS 的其他一些帖子:

回答by Matthew Daly

Any client-side framework like AngularJS isn't going to be bothered in the slightest by using just a vanilla Apache install, because it's pure client-side JavaScript.

任何像 AngularJS 这样的客户端框架都不会因为使用普通的 Apache 安装而受到丝毫干扰,因为它是纯客户端 JavaScript。

That said, it's a rare single-page web app that doesn't have at least some interaction with the web server via AJAX in order to fetch and amend the data stored there, and that's where you may need to consider what server you should use carefully. Ultimately you can build your back end with whatever server-side technology you feel is most appropriate, be that PHP, Python, Ruby, Node or whatever, and your choice of server will be dictated more by that than by your choice of client-side framework.

也就是说,这是一个罕见的单页 Web 应用程序,它至少没有通过 AJAX 与 Web 服务器进行一些交互以获取和修改存储在那里的数据,这就是您可能需要考虑应该使用什么服务器的地方小心。最终,您可以使用您认为最合适的任何服务器端技术来构建您的后端,无论是 PHP、Python、Ruby、Node 还是其他任何技术,您对服务器的选择将更多地由它决定,而不是由您选择的客户端决定框架。

I will add that I've often heard that Nginx is faster than Apache for serving static files, to the point that it's sometimes worth using Nginx for static files and reverse proxying to Apache for dynamic content. So it might make more sense to use Nginx than Apache for single page web apps. Personally I've used Nginx with Gunicorn for a Django app, and from what I've heard it's commonly used for both Ruby and Node.js applications as well. In the context of Node.js, I don't believe Node is generally used for serving static files in production, and from what I've heard the more usual arrangement is to have Nginx serve the static files and reverse proxy to the Node app for everything else.

我要补充一点,我经常听说 Nginx 在提供静态文件方面比 Apache 快,以至于有时值得将 Nginx 用于静态文件并反向代理到 Apache 以获取动态内容。因此,对于单页 Web 应用程序,使用 Nginx 比使用 Apache 可能更有意义。我个人已经将 Nginx 和 Gunicorn 用于 Django 应用程序,据我所知,它也常用于 Ruby 和 Node.js 应用程序。在 Node.js 的上下文中,我不相信 Node 通常用于在生产中提供静态文件,据我所知,更常见的安排是让 Nginx 提供静态文件并反向代理到 Node 应用程序对于其他一切。