Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • http:// site.com/image1.jpg

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

  • http:// s1.site.com/image1.jpg
  • http:// s1.site.com/image1.jpg
  • http:// s3.site.com/image1.jpg

Is this possible with nginx?

like image 772
user2350551 Avatar asked May 04 '13 19:05

user2350551


People also ask

What is load balancing in Nginx?

A load balancer acts as the “traffic cop” sitting in front of your servers and routing client requests across all servers capable of fulfilling those requests in a manner that maximizes speed and capacity utilization and ensures that no one server is overworked, which could degrade performance.

Is load balancing possible with Nginx?

It is possible to use nginx as a very efficient HTTP load balancer to distribute traffic to several application servers and to improve performance, scalability and reliability of web applications with nginx.

Is Nginx a l4 load balancer?

There are 2 types of Load Balancer that can be built using Nginx. First is Layer 4 Load Balancer, the second one is Layer 7 Load Balancer.

Is Nginx l7 load balancer?

The comprehensive Layer 7 load balancing capabilities in NGINX Plus enable you to build a highly optimized application delivery network. When you place NGINX Plus in front of your web and application servers as a Layer 7 load balancer, you increase the efficiency, reliability, and performance of your web applications.


1 Answers

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}";
    }
  }
like image 116
Jack Avatar answered Sep 29 '22 10:09

Jack