————————————————————————————————————————————————————————————————————————————————————————————————
nginx根据IP转发到指定的后端服务器
————————————————————————————————————————————————————————————————————————————————————————————————
详细配置见 ../nginx_conf/负载均衡、反向代理
————————————————————————————————————————————————————————————————————————————————————————————————
需求：
当用户请求IP为192.168.2.11时把后端请求转发到192.168.2.11服务器的8080端口

当用户请求IP为192.168.2.12时把后端请求转发到192.168.2.12服务器的8080端口

当请求的IP不是192.168.2.11和192.168.2.12时，将请求全部转发到192.168.2.66的8080端口

通过nginx实现

nginx配置如下
server {
    listen   80;
    access_log   /var/log/nginx/a.log;
 
    location / {
        proxy_ignore_client_abort on;
        proxy_read_timeout 200s;
        proxy_redirect    off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto  $scheme;
        client_max_body_size    1000m;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
 
        if ($remote_addr ~ "192.168.2.11")
        {
            proxy_pass    http://ip11;
            break;
        }
 
        if ($remote_addr ~ "192.168.2.12")
        {
            proxy_pass    http://ip12;
            break;
        }
 
        proxy_pass    http://ip66;
    }
}
upstream ip11 {
    ip_hash;
    server  192.168.2.11:8080 max_fails=5 fail_timeout=10;
}
 
upstream ip12 {
    server  192.168.2.12:8080 max_fails=5 fail_timeout=10;
}
 
upstream ip66 {
    server 192.168.2.66:8080 max_fails=5 fail_timeout=10;
}





