这里只提供了一种方式,针对location进行接口的定向分发。已最简单的配置说清楚接口定向分发,对于其他配置不做讲解。
比如请求两个URL:
1)、www.000.com/sale
2)、www.000.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.000.com;
- location /sale {
- root /www
- proxy_pass http://sale;
- }
-
- location /matchmaker {
- root /www
- proxy_pass http://matchmaker;
- }
- }
- }
说明:
当请求http://www.000.com/sale到达时,监听端口80端口的域名www.000.com根据location匹配到sale,然后根据字段proxy_pass http://sale去找到对应的upstream,这时请求就会到达192.168.1.100:8000这台机器。就做到了根据url定向转发实现负载均衡
根据 url 进行 负载均衡
原文:http://www.cnblogs.com/lnas01/p/5894150.html