Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

Thank you very much.

like image 785
JBT Avatar asked Mar 06 '14 12:03

JBT


People also ask

Can we run angular in Apache server?

We need to achieve 2 tasks: =>Serve the angular application from the Apache Server. =>The Apache Server must compress the contents of the angular build before serving it in the browser. To achieve these tasks, we need to make a few changes to the Apache24/conf/httpd.

How Angular application is deployed?

When you add a package with deployment capability, it'll automatically update your workspace configuration ( angular. json file) with a deploy section for the selected project. You can then use the ng deploy command to deploy that project. For example, the following command automatically deploys a project to Firebase.

What is production build in Angular?

ng build command compiles the Angular app into an output directory named dist/ at the given output path. This command must be executed from within the working directory. The application builder in Angular uses the webpack build tool, with configuration options specified in the workspace configuration file (angular.


2 Answers

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).

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:

  • Do not run 'grunt server' in production: can grunt server use for production application deployment
  • Run Apache/Nginx in production: Best way for deploy angular.js application made with yeoman?
  • Hosting server/client side together: The best deployment architecture for angularjs nodejs app
like image 130
marni Avatar answered Nov 28 '22 08:11

marni


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.

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.

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.

like image 24
Matthew Daly Avatar answered Nov 28 '22 09:11

Matthew Daly