zoukankan      html  css  js  c++  java
  • 根据 url 进行 负载均衡

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

    2)、www.xyz.com/matchmaker

     
     
    1. #user  nobody;  
    2. worker_processes  1;  
    3.   
    4. events {  
    5.     worker_connections  1024;  
    6. }  
    7.   
    8. http {  
    9.     include       mime.types;  
    10.     default_type  application/octet-stream;  
    11.     sendfile        on;  
    12.     keepalive_timeout  65;  
    13.     upstream sale {  
    14.         server 192.168.1.100:8000 max_fails=2;  
    15.      }  
    16.   
    17.     upstream matchmaker {  
    18.         server 192.168.1.200:8080 max_fails=2;  
    19.      }  
    20.   
    21.     server {  
    22.         listen       80;  
    23.         server_name  www.xyz.com;  
    24.         location /sale {  
    25.             root /www  
    26.             proxy_pass  http://sale;  
    27.         }  
    28.   
    29.         location /matchmaker {  
    30.              root /www  
    31.              proxy_pass http://matchmaker;  
    32.         }  
    33.     }  
    34. }  



    说明:
    当请求http://www.xyz.com/sale到达时,监听端口80端口的域名www.xyz.com根据location匹配到sale,然后根据字段proxy_pass  http://sale去找到对应的upstream,这时请求就会到达192.168.1.100:8000这台机器。就做到了根据url定向转发实现负载均衡
     
     
     
     
  • 相关阅读:
    99%的人都理解错了HTTP中GET与POST的区别
    idea 使用
    一道java算法题
    记一次jedis并发使用问题JedisException: Could not return the resource to the pool
    我珍藏的神兵利器
    记一次诡异的debug
    spring cloud config
    spring mvc 集成quartz
    git使用下
    Mongo--03 mongo副本集、备份与恢复
  • 原文地址:https://www.cnblogs.com/lnas01/p/5894150.html
Copyright © 2011-2022 走看看