Nginx sits in front of Node and handes all http requests from the client. This ensures Nginx is used for things it excels at like serving static assets, caching, and SSL.
If nginx determines that the incoming request is a static asset it will be served directly back to client without touching node.
If the request is not a static asset nginx will then pass it on to Node to process.
Node will query MongoDB for any required data.
Node will process the request and send the appropriate response back to the client.
For local development we will leverage a tool called StackStrap. This allows us to rapidly install and manage a Node environment that runs in a VM on the dev's machine.
Each StackStrap project has a template that acts as a blueprint for what needs to be installed for your environment. In our case we have a Node project template that installs the following:
StackStrap uses Vagrant and Salt, but marries the two together by providing an easier way to configure them. There is no requirement to be an expert with these tools, but it is still recommended that you familiarize yourself with them.
Before you install StackStrap ensure that you have met the below dependencies first.
Once the dependencies have been installed you are ready to install StackStrap from github:
$ sudo easy_install stackstrap
Once you have successfully installed StackStrap you will need to add the Node.js template that has already been created for you.
To add the the template to StackStrap run:
You will only run this command ONCE. New node projects will use this same template.
$ stackstrap template add django https://github.com/freesurface/stackstrap-django.git
Once you have successfully added the Node.js template you are ready to create a new project.
$ stackstrap create mynewproject django
$ cd mynewproject
$ vagrant up --provision
If all has gone well Vagrant will have started up a VM running your new project's Node.js environment.
When you create a new project with StackStrap it will set up a local domain name for you. This domain is assembled using your project name and system user name.
To test that it's working visit your project domain in a browser.
Close collaboration with the hosting provider will be necessary to ensure that production mirrors your local Node.js environment.
Vagrant Command Line Interface
$ vagrant ssh
$ vagrant up --provision
$ vagrant destroy
$ vagrant halt
If you are having issues connecting to your StackStrap domain try:
$ dscacheutil -flushcache