nginx 核心知识100讲笔记(二)

栏目: 服务器 · Nginx · 发布时间: 7年前

内容简介:对上游(比如tomcat)服务使用 keepalive 长连接以ip为基础, 即使上游服务端挂了, 也会一直访问一台服务器

反向代理

负载均衡策略 round-bobin 算法, 依次轮训, 挨个进行

  • weight 权重, 默认1
  • max_conns server的最大并发连接数, 仅作用于单worker
  • max_fails 在 fail_timeout 时间段内, 最大的失败次数. 当达到最大失败时候, 会在 fail_timeout 秒内这台server 不允许再次被选中
  • fail_timeout 单位时间秒, 默认10秒. 指定一段时间内, 最大是吧次数 max_fails. 到达 max_fails后, 该server不能访问的时间

对上游(比如tomcat)服务使用 keepalive 长连接

proxy_http_version 1.1; # 1.0 不支持长链接, 所以重置下, 为1.1
proxy_set_header Connection "";
upstream rrups {
    server 127.0.0.1:8011 weight=2 max_conns=2 max_fails=2 fail_timeout=5;
    server 127.0.0.1:8012;
    keepalive 32;
}

server {
    server_name rrups.liuhonghe.me;
    error_log myerror.log info;

    location /{
        proxy_pass http://rrups;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    }
}

负载均衡策略 ip_hash 算法

以ip为基础, 即使上游服务端挂了, 也会一直访问一台服务器

log_format  varups  '$upstream_addr $upstream_connect_time $upstream_header_time $upstream_response_time '
                        '$upstream_response_length $upstream_bytes_received '
                        '$upstream_status $upstream_http_server $upstream_cache_status';

upstream iphashups {
    #ip_hash;
    # curl -H 'X-Forwarded-for: 192.168.1.100 iphash.liuhonghe.me?username=abcdefg'
    hash user_$arg_username; # 使用特定字符串作为hash, 除非username更改, 否则不会更改
    server 127.0.0.1:8011 weight=2 max_conns=2 max_fails=2 fail_timeout=5; # 使用ip_hash 后权重不生效
    server 127.0.0.1:8012 weight=1;
}

server {
    set_real_ip_from  116.62.160.193;
    real_ip_recursive on;
    real_ip_header X-Forwarded-For;
    server_name iphash.liuhonghe.me;
    error_log myerror.log info;
    access_log logs/upstream_access.log varups;

    location /{
        proxy_pass http://iphashups;
        proxy_http_version 1.1;
            proxy_set_header Connection "";
    }
}

以上所述就是小编给大家介绍的《nginx 核心知识100讲笔记(二)》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

零边际成本社会

零边际成本社会

[美]杰里米·里夫金 / 赛迪研究院专家组 / 中信出版社 / 2014-11-1 / 49.00

在这本书中,《第三次工业革命》作者杰里米•里夫金开创性地探讨了极致生产力、协同共享、产消者、生物圈生活方式等全新的概念,详细地描述了数以百万计的人生产和生活模式的转变。他认为,“产消者”正在以近乎零成本的方式制作并分享自己的信息、娱乐、绿色能源和3D打印产品。他们也通过社交媒体、租赁商、合作组织以极低或零成本的模式分享汽车、住房、服装和其他物品;学生更多地参与到基于零成本模式的开放式网络课程…… ......一起来看看 《零边际成本社会》 这本书的介绍吧!

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具