• nginx实现均衡负载


    1.配置均很负载的服务端地址,http{}目录内

    # 均衡负载限制
        upstream gymserver{
                 #weight 值越大,负载权重越大,请求次数越多           
                 #max_fails 允许请求失败的次数,超过次数后,转发到下一个服务器,当有max_fails个请求失败,就表示后端的服务器不可用,默认为1,将其设置为0可以关闭检查   
                 #fail_timeout 指定时间内无响应则失败, 在以后的fail_timeout时间内nginx不会再把请求发往已检查出标记为不可用的服务器
                 #down 表示当前server不参与负载
                 #backup 其他非backup server都忙的时候,backup server作为备用服务器,将请求转发到backup服务器
            server 127.0.0.1:8070 weight=1 max_fails=2 fail_timeout=30s;
            server 127.0.0.1:8071 weight=2 max_fails=2 fail_timeout=30s;
        }

    2.配置需要代理的地址

    server {
            listen          80;
            server_name     api.baidu.com;
            # 服务器文件上传大小限制
            client_max_body_size 10M;
            location / {
                proxy_pass   http://gymserver;
            }
        }

    3.只需要这么简单的配置即可实现均衡负载(全配置截图如下)

    #user  nobody;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
    
        #access_log  logs/access.log  main;
    
        sendfile        on;
        #tcp_nopush     on;
    
        #keepalive_timeout  0;
        keepalive_timeout  65;
    
        #gzip  on;
        
        # 均衡负载配置
        upstream gymserver{
                 #weight 值越大,负载权重越大,请求次数越多           
                 #max_fails 允许请求失败的次数,超过次数后,转发到下一个服务器,当有max_fails个请求失败,就表示后端的服务器不可用,默认为1,将其设置为0可以关闭检查   
                 #fail_timeout 指定时间内无响应则失败, 在以后的fail_timeout时间内nginx不会再把请求发往已检查出标记为不可用的服务器
                 #down 表示当前server不参与负载
                 #backup 其他非backup server都忙的时候,backup server作为备用服务器,将请求转发到backup服务器
            server 127.0.0.1:8070 weight=1 max_fails=2 fail_timeout=30s;
            server 127.0.0.1:8071 weight=2 max_fails=2 fail_timeout=30s;
        }
        
        
        server {
            listen       80 default_server;
            server_name  _;
           location / {
                root   html;
                index  index.html index.htm;
            }
        }
    
    
        server {
            listen          80;
            server_name     baidu.com;
            root            /www/html/jsfadmin;
    
            location / {
                try_files $uri $uri/ /index.html;
            }
        }
        
        
        server {
            listen          80;
            server_name     www.baidu.com;
            root            /www/html/jsfadmin;
    
            location / {
                try_files $uri $uri/ /index.html;
            }
        }
        
        
        server {
            listen          80;
            server_name     api.baidu.com;
            # 服务器文件上传大小限制
            client_max_body_size 10M;
            location / {
                proxy_pass   http://gymserver;
            }
        }
    
    }
  • 相关阅读:
    关于在调用JAVAFX相关包时遇到Access restriction: The type 'Application' is not API (restriction on required library)的解决方法
    JS 获取随机颜色值
    JS jQuery 点击页面漂浮出文字
    JQ 获取浏览器窗口宽高
    JQ 操作css
    JQ 遍历--(祖先,后代,同胞,过滤)
    JQ DOM元素 创建 添加 删除
    jQuery 效果
    3
    webpack 打包CSS 引入图片
  • 原文地址:https://www.cnblogs.com/hjieone/p/14735306.html
Copyright © 2020-2023  润新知