• Nginx作为负载均衡服务器——server参数讲解


    upstream举例
            

     upstream backend {
    
            server backend1.ecample.com       weight = 5;  # wwight 代表权重
            server backend2.ecample.com:8080;
            server unix:/tmp/backend3;
    
            server backend1.com       backup;        # backup 代表备份
            server backend2.com:8080;  backup;          
    
    }

    后端服务器在负载均衡调度中的状态

    演示:

    配置.conf文件

    upstream test {
            server 192.168.96.188:8001   down;
            server 192.168.96.188:8002;   backup;     # 预留的备份服务器
            server 192.168.96.188:8003;   max_fails=1 fail_timeout=10s;  # 经过max_fails失败后,服务暂停的时间
    
    	}
    
    server {
        listen       80;
        server_name  localhost www.test.com;
    
        #charset koi8-r;
        #access_log  /usr/local/nginx/logs/test_proxy.access.log  main;
        resolver  8.8.8.8;
        
        location / {
            proxy_pass http://test;
            include proxy_params;
        }
    
        #error_page  404              /404.html;
    
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
    
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ .php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }
    

    访问目标主机192.168.96.146。刷新之后,只能访问到server3

    将192.168.96.188的这台主机server3这个服务停掉。然后再访问192.168.96.146。这时候只能访问到备份的server2

  • 相关阅读:
    php 条件语句
    MySQL笔记整理任务
    MySQL高可用之PXC
    MySQL高可用之MHA
    虚拟机现有网卡为仅主机模式,需要添加第二块网卡实现上网功能
    Shiro学习
    vue环境搭建
    SpringBoot修改日志的默认配置
    springboot的配置文件application.properties详解
    安装MySQL报错Install/Remove of the Service Denied
  • 原文地址:https://www.cnblogs.com/joy-sir/p/12162687.html
Copyright © 2020-2023  润新知