Nginx As Loadbalancer

In order to get NGINX working as load balancer the following steps are needed on a Mac:

1. Install NGINX via brew

brew install nginx

2. Create/Edit nginx.conf (default: /usr/local/etc/nginx/)

events {
    worker_connections  1024;
}


http {
  upstream customers {
    server localhost:8080 weight=3;
    server localhost:8081;
  }

  server {
    listen 80;
    location / {
      proxy_pass http://customers;
    }
  }
}

3. Update /etc/hosts (optional)

127.0.0.1       localhost,customers

Some Notes

nginx
nginx -s stop

A very interesting read: http://tenzer.dk/nginx-with-dynamic-upstreams/