搜索

首页  >  问答  >  正文

nginx根据域名进行负载均衡问题

问题

upstream ops {
    #ip_hash;
    server 5000.ali-bj.cloud.net:10080 weight=2 max_fails=1 fail_timeout=2;
    server 5000.ali-sh.cloud.net:10080 weight=1 max_fails=1 fail_timeout=2;
    #server 192.168.0.4:5000 max_fails=1 fail_timeout=2;
    #server 127.0.0.1:12309;
    #server 127.0.0.1:12310;
    #server 127.0.0.1:10080 ;
}
----
#web.conf主要配置
    location / {
        add_header Version v3.1.5.3;
        add_header Os QingDao.aliyun.Debian8;
        proxy_set_header         X-Via            QingDao.Aliyun;
        proxy_set_header         Connection       "";
        proxy_set_header         Host             $http_host;
        proxy_set_header         X-Real_IP        $remote_addr;
        proxy_set_header         X-Forwarded-For  $proxy_add_x_forwarded_for;
        proxy_pass http://ops;
        proxy_cache opscache;
        proxy_cache_valid 200 302 5m;
        proxy_cache_valid 301 1h;
        proxy_cache_valid any 1m;

    }

说明:

5000.ali-bj.cloud.net/5000.ali-sh.cloud.net 域名都是解析到同一个ip(192.168.1.124)上的

访问域名502:

2017/04/03 11:26:14 [error] 408#408: *1 upstream prematurely closed connection while reading response header from upstream, client: 192.168.1.105, server: dev.cloud.net, request: "GET / HTTP/1.1", upstream: "http://192.168.1.124:10080/", host: "dev.cloud.net"

疑问?

nginx upstream可以根据域名进行负载均衡吗?设置了Host $http_host还是一样的

黄舟黄舟2751 天前773

全部回复(1)我来回复

  • 给我你的怀抱

    给我你的怀抱2017-05-16 17:10:23

    很明显nginx是支持虚拟主机的!然后不同的虚拟主机定义不同的upstream不就行了!

    回复
    0
  • 取消回复