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

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

    在upstream中配置具体负载均衡信息
    通过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;
    }

    豌豆资源搜索网站https://55wd.com 广州vi设计公司http://www.maiqicn.com

    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,每次路由到同一台后端服务上

  • 相关阅读:
    【每日scrum】5.3
    Scrum仪式之Sprint计划会议
    软工结队开发--成员介绍
    java反射保存
    java后台开发传输乱码&&接口post传参失败
    润乾报表之分组
    润乾报表之居中无效(去空格)
    润乾报表之日期格式、小数位数
    润乾报表之序号、固定行数、统计
    润乾报表之条形码
  • 原文地址:https://www.cnblogs.com/qianxiaox/p/13719190.html
Copyright © 2011-2022 走看看