zoukankan      html  css  js  c++  java
  • nginx配置http负载均衡

     

    nginx配置负载均衡需要有两个关键配置

    1. 在upstream中配置具体负载均衡信息

    2. 通过proxy_pass 来引用已经配置好的负载均衡信息

    在http{}部分引入mylb.conf文件

    http {
      include       /etc/nginx/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 /var/log/nginx/access.log main;

      sendfile       on;
      #tcp_nopush     on;

      keepalive_timeout 65;

      #gzip on;

      include /etc/nginx/conf.d/*.conf;
    }

     

    mylb.conf内容如下

    server {
      listen       8000;
      server_name localhost;
      location / {
    proxy_pass http://springboot;
    proxy_next_upstream http_502 http_504 http_404 error timeout invalid_header;
          root   /usr/share/nginx/html;
          index index.html index.htm;
      }
      error_page   500 502 503 504 /50x.html;
      location = /50x.html {
          root   /usr/share/nginx/html;
      }


    }
    upstream springboot{
          server 192.168.43.85:8764 max_fails=1 fail_timeout=10s;
          server my.com:8764 max_fails=1 fail_timeout=10s ;
          hash $cookie_jsessionid;
    }

    主要配置为

    1. server下面的listen,表示监听的端口

    2. location标识匹配的路径

    3. proxy_pass路径匹配以后的upstream名字

    4. upstream里面配置的为负载均衡的具体内容

    5. 其中server 后面配置的为负载到的服务的机器ip和端口

    6. max_fails:失败重试次数

    7. fail_timeout:超时时间

    8. hash $cookie_jsessionid;根据jsession做会话保持。会对jsessionid做一个hash,每次路由到同一台后端服务上

  • 相关阅读:
    怎样使用两行代码实现博客园打赏功能
    使用vue开发微信公众号下SPA站点的填坑之旅
    贝叶斯公式与最大后验估计(MAP)
    多元高斯分布(The Multivariate normal distribution)
    Jacobian矩阵、Hessian矩阵和Newton's method
    导数、方向导数与梯度
    解决只有单引号的Json格式转换成bean问题
    浅析Java中的final关键字
    观察者模式/ java实现附代码 /
    Java内存区域与内存溢出异常
  • 原文地址:https://www.cnblogs.com/liguangming/p/13371685.html
Copyright © 2011-2022 走看看