Nginx之——针对URL实现负载均衡或者说接口定向分发

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/65936335

这里只提供了一种方式,针对location进行接口的定向分发。
已最简单的配置说清楚接口定向分发,对于其他配置不做讲解。
比如请求两个URL:
1)、www.lyz.com/sale
2)、www.lyz.com/matchmaker

#user  nobody;
worker_processes  1;
 
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    upstream sale {
        server 192.168.1.100:8000 max_fails=2;
     }
 
    upstream matchmaker {
        server 192.168.1.200:8080 max_fails=2;
     }
 
    server {
        listen       80;
        server_name  www.lyz.com;
        location /sale {
            root /www
            proxy_pass  http://sale;
        }
 
        location /matchmaker {
             root /www
             proxy_pass http://matchmaker;
        }
    }
}

当请求http://www.lyz.com/sale到达时,监听端口80端口的域名www.lyz.com根据location匹配到sale,然后根据字段proxy_pass  http://sale去找到对应的upstream,这时请求就会到达192.168.1.100:8000这台机器。
就做到了根据url定向转发实现负载均衡

猜你喜欢

转载自blog.csdn.net/zpz_326/article/details/81335307