首页 > nginx > nginx的Split Clients模块

nginx的Split Clients模块

2011年4月1日 eric 发表评论 阅读评论

nginx 官网上浏览这些日子nginx 的更新,看到 更新了Split Clients 的模块·然后就看了一下·发现官网wiki的几点问题·写帮助文档的人有些不负责,我编译安装后,按照wiki的方法配置nginx.conf 报错。

官网wiki :

http://wiki.nginx.org/HttpSplitClientsModule

http {
    split-clients "${remote-addr}AAA" $variant {
        0.5% .one;
        2.0% .two;
        - "";
    }

    server {
        location / {
             index index${variant}.html;

我实际的代码是:

http {
    split_clients "${remote_addr}AAA" $variant {
        0.5% .one;
        2% .two;
        3% .eric;
        4% .yang;
        50% .thr;
        * "";
    }

    server {
        location / {
             index index${variant}.html;
    }

然后新建几个文件

cd /usr/local/nginx/html/

echo "one" >index.one.html
echo "two" >index.two.html
echo "eric" >index.eric.html
echo "thr" >index.thr.html

配置差别:

wiki : split-clients     eric:split_clients
wiki : remote-addr       eric: remote_addr
wiki :  - "";            eric: * "";

关于这些错误的发现是因为 nginx 有 remote_addr 变量 并没有 remote-addr ·我就顺藤摸瓜·

随后我来讲下 Split Clients模块的一点点知识,我自己时间测试出来的~
关于测试,我们在 nginx 的错误日志上 输出 ${variant} 变量

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for" "$variant"';

以便于我们测试结果。

Split Clients 的模块 模块 是切割 客户端IP 然后然后 使用CRC32的 算出一个值去匹配·
在 俄文网站上 翻译出这么一段:

该指令创造了A / B分割一变
测试,例如: 

http {
    split_clients "${remote_addr}AAA" $variant {
        0.5% .one;
        2% .two;
        * "";
    }
原来的字符串变量的值是哈希
使用CRC32的。在这个例子中,当
哈希值从0到21474836(0.5%),变量$变种
有值“。之一”。如果哈希值21474837
至107374182(2%) - “。两个”。而如果从107374183哈希值
4294967297 - “”。

也就是说,比如 我的IP地址是 192.168.1.29 服务器IP 为 192.168.1.28
当我访问 nginx 的时候,nginx 会切割我的IP地址 匹配到 .1
日志:

192.168.1.29 - - [01/Apr/2011:15:39:17 +0800] "GET / HTTP/1.1" 403 571 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)" "-" ".thr"

看到的页面是 thr

当我修改我的 IP 为 192.168.220.29 服务器IP 为 192.168.220.28
在看日志:

192.168.220.29 - - [01/Apr/2011:15:44:46 +0800] "GET / HTTP/1.1" 403 571 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)" "-" ".two"

看到的页面是 two

PS:这样的画 nginx 里的$variant 变量 可以给我们带来各种好处了·判断来自哪个IP段的分到哪个服务器上~!

转载请注明:文章转载自:Eric's linux and nginx! (http://www.nginxs.com)
本文地址:http://www.nginxs.com/linux/455.html

分类: nginx 标签: , ,
  1. 2018年4月23日12:35 | #1

    I loved as much as you’ll receive carried out right here. The sketch is tasteful, your
    authored subject matter stylish. nonetheless, you command get bought an shakiness over that you wish be delivering the following.
    unwell unquestionably come more formerly again since exactly the same
    nearly very often inside case you shield this hike.

  2. 2018年4月23日15:28 | #2

    Hi to all, how is all, I think every one is getting more from
    this site, and your views are nice designed for new people.

  3. 2018年4月23日16:41 | #3

    Its like you read my mind! You seem to know a
    lot about this, like you wrote the book in it or something.
    I think that you could do with some pics to drive the message home
    a bit, but instead of that, this is magnificent blog.
    A fantastic read. I will certainly be back.

  4. 2018年4月23日20:52 | #4

    What’s Taking place i am new to this, I stumbled upon this
    I’ve discovered It absolutely helpful and it has aided me out
    loads. I’m hoping to give a contribution & aid other customers like its aided me.
    Great job.

  5. 2018年4月24日05:32 | #5

    I am regular visitor, how are you everybody? This piece of writing posted at this web page is actually nice.

  6. 2018年4月24日05:39 | #6

    Helpful information. Lucky me I found your site unintentionally, and I am shocked why this
    twist of fate did not took place in advance! I bookmarked it.

  7. 2018年4月24日06:25 | #7

    Hello my family member! I wish to say that this article is amazing, nice written and include almost all vital infos.
    I’d like to peer more posts like this .

  8. 2018年4月24日07:32 | #8

    The most recent development is to opt for concrete flooring.

  9. 2018年4月24日07:41 | #9

    My spouse and I stumbled over here from a different website and thought I should check things out.
    I like what I see so now i am following you. Look forward to going over your
    web page for a second time.

  10. 2018年4月24日22:06 | #10

    Wooden Shake or Composite Roofing – Restore.

  11. 2018年4月24日22:40 | #11

    Hello to every single one, it’s in fact a fastidious for me to go to see this web
    page, it contains valuable Information.

  12. 2018年4月24日23:18 | #12

    Hey very nice blog!

  13. 2018年4月25日00:12 | #13

    Hi! I’ve been reading your site for a long time
    now and finally got the bravery to go ahead and give you a shout out from New Caney Texas!
    Just wanted to mention keep up the excellent work!

  14. 2018年4月25日00:45 | #14

    Because the admin of this web page is working, no doubt very quickly it will be well-known, due to its
    feature contents.

  15. 2018年4月25日01:03 | #15

    Thanks very interesting blog!

  16. 2018年4月25日03:01 | #16

    I used to be recommended this website by means of my cousin. I’m no longer positive whether this submit is written by way of him
    as no one else understand such certain approximately my trouble.
    You are wonderful! Thank you!

  17. 2018年4月25日05:04 | #17

    I always spent my half an hour to read this webpage’s articles daily along
    with a mug of coffee.

  18. 2018年4月25日07:57 | #18

    With havin so much written content do you ever run into any issues of plagorism or copyright infringement?
    My site has a lot of unique content I’ve
    either created myself or outsourced but it looks like a lot of it is popping
    it up all over the web without my permission. Do you know any techniques to help prevent content from being stolen? I’d truly appreciate it.

  19. 2018年4月25日08:37 | #19

    Hello there! Do you know if they make any plugins to assist
    with SEO? I’m trying to get my blog to rank for some targeted
    keywords but I’m not seeing very good gains.
    If you know of any please share. Thank you!

  20. 2018年4月25日09:48 | #20

    Good day! Do you know if they make any plugins to protect against hackers?
    I’m kinda paranoid about losing everything I’ve worked hard on.
    Any suggestions?

  21. 2018年4月25日10:58 | #21

    Very good article. I will be experiencing many of these issues as well..

  22. 2018年4月25日14:26 | #22

    Fine way of describing, and pleasant post
    to get data concerning my presentation focus, which i am going to present
    in university.

评论分页
1 2 455
订阅评论
4+4= (必填)