[Java] 纯文本查看 复制代码
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;
}
}