Logging in and updating system to latest
SSH your shiny new VM,
Now lets update the system to the latest:
1
|
|
Install OS dependencies
We’r going to build Node.js from sources, some dependencies (such as gcc) are required:
1
|
|
Cloning n Building Node.js
1 2 3 4 5 6 7 |
|
Configuration
1 2 3 |
|
Put your app
Now put your app in ~, for instance:
1 2 3 4 |
|
Init.d
We would like to have nodejs to start automatically as a service, to do so, lets create an init.d file Note: you have to change the properties in the file such as yourappuser, myapp to your app folder and server.js to your node app file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
Add execution permission to the nodejs init script
1
|
|
Pre Routing to port 80
Linux does not allow non super users to listen to ports < 1024, assuming your application listen to port 8080, You would probably like to pre route any traffic arriving from port 80 to your node app that listens to port 8080
You can do this by the pre routing nat capability of Iptables
1 2 3 4 5 |
|
Configuring node-http-proxy ##
It is common to install http proxies such as nginx on front of nodejs, This architecture has many advantages such as raising security level, listening natively to port 80, load balancing, multiple node apps support via url rewrite, etc…
I personally think that the best approach, which is very native to node apps is to use https://github.com/nodejitsu/node-http-proxy,
Which have several advantages:
Reverse proxies incoming http.ServerRequest streams, WebSockets, HTTPS Minimal request overhead and latency Battled-hardened through production usage Very native for nodejs apps TODO: Will post more details in the future but you can simply visit “https://github.com/nodejitsu/node-http-proxy%E2%80%9D site.