Nginx反向代理的模拟

时间:2023-03-09 09:02:56
Nginx反向代理的模拟

CentOS起两台tomcat,端口分别是8080和8081!

1.

Nginx反向代理的模拟

Nginx反向代理的模拟

nginx配置文件:nginx.conf

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

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

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

Nginx反向代理的模拟

当然了,需要配一下hosts,使用这个好工具

Nginx反向代理的模拟

上述情况负载均衡的处理

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

upstream tomcats{
    server 192.168.198.128:8080 weight=5;
    server 192.168.198.128:8081;
}

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

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