根據 url 進行 負載平衡

來源:互聯網
上載者:User

標籤:

這裡只提供了一種方式,針對location進行介面的定向分發。已最簡單的配置說清楚介面定向分發,對於其他配置不做講解。比如請求兩個URL:1)、www.000.com/sale

2)、www.000.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.000.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.000.com/sale到達時,監聽連接埠80連接埠的網域名稱www.000.com根據location匹配到sale,然後根據欄位proxy_pass  http://sale去找到對應的upstream,這時請求就會到達192.168.1.100:8000這台機器。就做到了根據url定向轉寄實現負載平衡    

根據 url 進行 負載平衡

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.