I was wondering if it was possible to use a single Nginx server to load balance my web servers and api servers if both are using port 80. In this setup there would be 5 servers, 1 Nginx and 4 Apache servers. I would like the web servers to be balanced when web.example.com is accessed. Likewise, I would like the api servers to be balanced when api.example.com is accessed.
Is this possible or do I need another nginx server?
Best Answer
You have two possible approach :
1. A single VIP for both farms :
In this case, your VIP will be your
NGinx
server single ip address.2. A dedicated VIP for each farms
In that case you need two IP Address on the
NGinx
host.Let's say :
192.168.1.2 for Api (eth1)
Then you have multiple options to manage load-balancing and failover in
upstream
directive, like :weight
max_fails
fail_timeout
http://wiki.nginx.org/NginxHttpUpstreamModule#upstream
Also, you have multiple load-balancing method :
least-connected
Session persistence
http://nginx.org/en/docs/http/load_balancing.html