HttpIndex模块

这个模块提供一个简单方法来实现在轮询和客户端IP之间的后端服务器负荷平衡。

配置范例:

  1. upstream backend {
  2. server backend1.example.com weight=5;
  3. server backend2.example.com:8080;
  4. server unix:/tmp/backend3;
  5. }
  6. server {
  7. location / {
  8. proxy_pass http://backend;
  9. }
  10. }

配置指导

ip_hash

syntax: ip_hash

default: none

context: upstream

This directive causes requests to be distributed between upstreams based on the IP-address of the client. The key for the hash is the class-C network address of the client. This method guarantees that the client request will always be transferred to the same server. But if this server is considered inoperative, then the request of this client will be transferred to another server. This gives a high probability clients will always connect to the same server.

范例:

  1. upstream backend {
  2. ip_hash;
  3. server backend1.example.com;
  4. server backend2.example.com;
  5. server backend3.example.com down;
  6. server backend4.example.com;
  7. }

server

syntax: server name [parameters]

default: none

context: upstream