<返回更多

nginx web负载均衡配置

2022-07-08    新生代程序员
加入收藏

Nginx web负载均衡配置

下载nginx

wget http://nginx.org/download/nginx-1.20.2.tar.gz

安装nginx

./configure --prefix=/opt/nginx
或
./configure --prefix=/opt/nginx --with-http_ssl_module
make
make install

报错

yum -y install pcre-devel
yum -y install zlib-devel
yum -y install openssl openssl-devel

nginx限制请求数据包大小

client_max_body_size 1000m;

负载均衡配置

  upstream test_group {
        # If there is no specific strategy, round-robin
        #     would be the default strategy.
        # least_conn;
        # ip_hash;
        server 172.16.217.109:8501 weight=1 max_fails=2 fail_timeout=30s;
        server 172.16.217.109:8502 weight=1 max_fails=2 fail_timeout=30s;
    }
    
    location / {
            #root   html;
            #index  index.html index.htm;
            client_max_body_size 3m;
            proxy_pass http://test_group;
    }

nginx负载均衡策略

轮询

upstream my_server{
    server IP:8080;
    server IP:8081;
}
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    location / {
        proxy_pass http://my_server/;
    }
}

权重

upstream my_server{
    server IP:8080 weight=10;
    server IP:8081 weight=2;
}
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    location / {
        proxy_pass http://my_server/;
    }
}

ip_hash

upstream my_server{
    ip_hash;
    server IP:8080 weight=10;
    server IP:8081 weight=2;
}
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    location / {
        proxy_pass http://my_server/;
    }
}
声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>