nginx配置反向代理和负载均衡

一、反向代理

  说明:应该有一个nginx服务器有多个应用服务器(可以是tomcat),本文使用一台虚拟机,安装一个nginx,多个tomcat,来模拟

upstream tomcats{
	server 192.168.25.148:8080;
	server 192.168.25.148:8081;
}

server {
        listen       80;
        server_name  tomcat.test.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass   http://tomcats;
            index  index.html index.htm;
        }
}

 

二、负载均衡

  说明:只需要在upstream的server后面添加一个weight即可代表权重。权重越高,分配请求的数量就越多。默认权重是1

upstream tomcats{
	server 192.168.0.11:8080 weight=2;
	server 192.168.0.11:8081;
}

server {
        listen       80;
        server_name  tomcat.test.com;

        #charset koi8-r;
        
        #access_log  logs/host.access.log  main;
        
        location / {
            proxy_pass  http://tomcats;
            index  index.html index.htm;
        }
}

至此简单的nginx反向代理和负载均衡配置结束……

 

关注我的公众号,精彩内容不能错过

 

转载于:https://www.cnblogs.com/huanchupkblog/p/5562519.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值