0

I'm having a demo this coming week and I need to deploy the application I'm working on (developed using MEANjs stack) preferably to a server like nginx or the like.
I'm behind a Red-hat box so my question is what would be the best practices when deploying an application to production

  • Does a deploy to nginx is viable? (redhat box has already installed apache, do I need to interchange with nginx?)
  • is there any notes on what to and not to do for this process?

I've found this How to deploy MEAN.js (Node.js) application to Production environment

and I was trying to comment but don't have the required points :D so anyway, don't quite understand the nginx part(putting in front) so that means that you don't actually deploy the app into nginx ?

I've also look at other questions like:

so its like do we really need ningx, apache or the like from the best practices perspective?, or the way to go is just rsync the content to a production server folder and start your app with Upstart?

what about using Passenger with MEANjs anyone used this?

EDIT:

Alright so I have my meanjs server running on port 8002 below is my configuration for ningx, which is working as far as I can tell allright, now what about securing this setup?

EDIT2: Well I'm learning here so this is what I found https://groups.google.com/forum/#!topic/meanjs/_Kb07-tvlzU
apparently in order to deploy this after running the "grunt build" command just run it like so :

node server.js

and apparently it will get all your configuration from production.js
Not completely sure if it would be production ready.
and now I think I should move this to somewhere like /var/www/theAppFolder/ for organizational sake.

this is nginx configuration

upstream proj{
  server 127.0.0.1:8002;
}

server{
  listen 0.0.0.0:80;
    server_name dep01.local  poc;
    access_log /var/log/nginx/dep01.log;

    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://proj/;
      proxy_redirect off;
    }
}
Community
  • 1
  • 1
yokodev
  • 1,266
  • 2
  • 14
  • 28
  • I think you need to understand what your application does and what all of the parts are. Nginx and Apache are **web** servers, and are commonly used to proxy to your Node.js **application** server. You don't need to use Nginx, but its threading model is much more efficient than Apache. No matter which you use, you need to configure them to point at your Node.js application. As far as anything else for deployment goes, it depends entirely on what your specific needs are. Do what you need to do... that's about as specific as I can get with the information presented here. – Brad Aug 19 '14 at 16:05

1 Answers1

1

Deploying your node app behind nginx is definitely viable.

Your red hat box is ok to host birth servers.

You need to install both node and nginx to the server.

Then deploy node app so it listens to some high port, say 8000. You also setup your app to trust it's proxy (which is what nginx will do). For security reasons, you can only slow connections to the node port from localhost.

Now go on and configure nginx.You can, for example, set an "upstream" in the config to point to localhost:8000. Then stop a virtual host in nginx conf for your app and domain and proxy requests to the previously defined upstream.

You can smash set any SSL certificates on nginx, that way i it will be more performant (node tends to be much slower then nginx with SSL).

alternatively, you can just bind node directly to port 80 (and 443 for SSL) and skip using nginx, but that depends on the server, the app, the audience and environment and your personal preferences and experiences.

For details about any of the steps, try providing more details.

Zlatko
  • 18,936
  • 14
  • 70
  • 123
  • I edited my question.., "you also setup your app to trust it's proxy (which is what nginx will do). For security reasons, you can only slow connections to the node port from localhost. ", can you elaborate a little bit more about this. based on the configuration that I have so far.. Thanks – yokodev Aug 22 '14 at 20:04
  • By proxy, I mean you *app.set('trust proxy');* So that node.js trusts your nginx. – Zlatko Aug 22 '14 at 21:44
  • Also, about your updated question. You are trying (it seems) to execute client side code with Node.js. You should not. You should include that in your frontend pages instead of all the unminified scripts and test it in browser. – Zlatko Aug 22 '14 at 21:45
  • I re-edited again, and I think I'm just missing the UPSTAR part and for the demo it will suffice Thanks again, any other suggestion are very wellcome – yokodev Aug 22 '14 at 22:06