This is a sample repo I created for the express purpose of learning and becoming familiar with how to setup NGINX service in front of Node.js servers. Specifically in this particular case, I've configured NGINX as a reverse proxy and load balancer, load balancing 2 Node.js servers behind it.
- Install
nginx
on system by runningbrew install nginx
- Copy
nginx.conf
file in this repo to/usr/local/etc/nginx
- Run
npm install
in repo to install npm modules, mainly express - Run
npm start
to start up Node server instances (server #1 on localhost:8080 and #2 on localhost:8081) - Run
brew services start nginx
to startup the NGINX service athttp://localhost:8080
- Open browser to
http://localhost:8080
and refresh page a few times.
You should see a page with the message "Hello World from Node Server #1" or "Hello World from Node Server #2". This is effectively NGINX handling the request and proxying to the 2 Node servers using round-robin load balancing.
- Installing NGINX on MacOSX: http://learnaholic.me/2012/10/10/installing-nginx-in-mac-os-x-mountain-lion/