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

  • 相关阅读:
    Hello world
    Kubernetes容器云平台建设实践
    工作方法决定自己的发展
    Excel中对身份证号的处理
    详解慢查询日志的相关设置及mysqldumpslow工具
    安全测试工具简介
    Redis使用
    linux centos 查看防火墙firewalld、iptables状态
    悄悄地存在这里,因为里面的一句话
    GAE Python 2009322
  • 原文地址:https://www.cnblogs.com/qianxiaox/p/13719190.html
Copyright © 2020-2023  润新知