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