+【原创】+nginx负载均衡

本文详细介绍了如何使用Nginx进行负载均衡配置,包括基本的服务器集群设置和基于权重的负载分配策略,以实现不同性能服务器之间的合理任务分配。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

概念:
      负载均衡建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备服务器的带宽、增加吞吐量、加强网络数据处理能力、提高网络的灵活性和可用性nginx:配置
      

[Java] 纯文本查看 复制代码
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
upstream tomcatserver1 {
        server 192.168.3.43:8080;
        server 192.168.3.43:8082; #多加了此台服务器
}
    upstream tomcatserver2 {
        server 192.168.3.43:8082;
    }
   server {
        listen       80;
        server_name  8080.zcinfo.com;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            proxy_pass   http://tomcatserver1;
            index  index.html index.htm;
        
    }
    server {
        listen       80;
        server_name  8082.zcinfo.com;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            proxy_pass   http://tomcatserver2;
            index  index.html index.htm;
        }
    }
如果两台服务器性能差不多这样设置重启nginx就行了,但是现在假如两台服务器性能不一样,还需要设置性能权重,让性能高服务器做更多事情。只需要加入weight=?就行了,如下:
 
upstream tomcatserver1 {
        server 192.168.3.43:8080 weight=2;
        server 192.168.3.43:8082 weight=1;
}
    upstream tomcatserver2 {
        server 192.168.3.43:8082;
    }
   server {
        listen       80;
        server_name  8080.zcinfo.com;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            proxy_pass   http://tomcatserver1;
            index  index.html index.htm;
        
    }
    server {
        listen       80;
        server_name  8082.zcinfo.com;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            proxy_pass   http://tomcatserver2;
            index  index.html index.htm;
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值