imagenginxhttp-redirectproxyload-balancing

Nginx Load Balancing


I want to load balance my website with nginx.

The load balancing in nginx wiki is proxy, so the actual file being downloaded from the frontend server. (http://wiki.nginx.org/LoadBalanceExample)

This is how I need the balancing:

user request file:

nginx redirect user to one of the servers (with Location header):

Is this possible with nginx?


Solution

  • http {
      split_clients "${remote_addr}" $server_id {
        33.3% 1;
        33.3% 2;
        33.4% 3;
      }
    
      server {
        location ~* \.(gif|jpg|jpeg)$ {
          return 301 "${scheme}://s${server_id}.site.com${request_uri}";
        }
      }