您当前的位置:首页 > 计算机 > 服务器 > Nginx

nginx 负载均衡

时间:07-06来源:作者:点击数:

1.负载均衡

    upstream imooc {
        server 116.62.103.228:8001;
        server 116.62.103.228:8002;
        server 116.62.103.228:8003;
    }

server {
    listen       80;
    server_name  localhost jeson.t.imooc.io;

    #charset koi8-r;
    access_log  /var/log/nginx/test_proxy.access.log  main;
    resolver  8.8.8.8;
    
    location / {
        proxy_pass http://imooc;(默认是轮训)
        include proxy_params;
    }
    upstream imooc {
        server 116.62.103.228:8001 down;
        server 116.62.103.228:8002 backup;
        server 116.62.103.228:8003 max_fails=1 fail_timeout=10s;
    }

server {
    listen       80;
    server_name  localhost jeson.t.imooc.io;

    #charset koi8-r;
    access_log  /var/log/nginx/test_proxy.access.log  main;
    resolver  8.8.8.8;
    
    location / {
        proxy_pass http://imooc;
        include proxy_params;
    }

1.加权

    upstream imooc {
        server 116.62.103.228:8001;
        server 116.62.103.228:8002 weight=5(加权轮训);
        server 116.62.103.228:8003;
    }

server {
    listen       80;
    server_name  localhost jeson.t.imooc.io;

    #charset koi8-r;
    access_log  /var/log/nginx/test_proxy.access.log  main;
    resolver  8.8.8.8;
    
    location / {
        proxy_pass http://imooc;
        include proxy_params;
    }

2.ip分配 

    upstream imooc {
        ip_hash;(ip分配)
        server 116.62.103.228:8001;
        server 116.62.103.228:8002;
        server 116.62.103.228:8003;
    }

server {
    listen       80;
    server_name  localhost jeson.t.imooc.io;

    #charset koi8-r;
    access_log  /var/log/nginx/test_proxy.access.log  main;
    resolver  8.8.8.8;
    
    location / {
        proxy_pass http://imooc;
        include proxy_params;
    }

3.hash

    upstream imooc {
        hash $request_uri;
        server 116.62.103.228:8001;
        server 116.62.103.228:8002;
        server 116.62.103.228:8003;
    }

server {
    listen       80;
    server_name  localhost jeson.t.imooc.io;

    #charset koi8-r;
    access_log  /var/log/nginx/test_proxy.access.log  main;
    resolver  8.8.8.8;
    
    location / {
        proxy_pass http://imooc;
        include proxy_params;
    }
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门