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

  • 相关阅读:
    广域网(ppp协议、HDLC协议)
    0120. Triangle (M)
    0589. N-ary Tree Preorder Traversal (E)
    0377. Combination Sum IV (M)
    1074. Number of Submatrices That Sum to Target (H)
    1209. Remove All Adjacent Duplicates in String II (M)
    0509. Fibonacci Number (E)
    0086. Partition List (M)
    0667. Beautiful Arrangement II (M)
    1302. Deepest Leaves Sum (M)
  • 原文地址:https://www.cnblogs.com/liguangming/p/13371685.html
Copyright © 2011-2022 走看看