首页 > 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年5月25日15:43 | #1

    payday lending payday lender private money lenders [url=https://paydaylending.us.org]payday lending[/url]

  2. 2018年5月25日15:48 | #2

    Hi everyone, it’s my first pay a visit at this site, and
    piece of writing is in fact fruitful designed for me, keep up posting such
    content.

  3. 2018年5月25日19:04 | #3

    I go to see everyday some blogs and blogs to read articles, except this website presents feature based articles.

  4. 2018年5月26日03:25 | #4

    Unquestionably imagine that that you said. Your favourite justification seemed to be at the
    net the simplest thing to be aware of. I say to you, I definitely get irked
    whilst folks consider worries that they just do not recognise about.
    You managed to hit the nail upon the highest as neatly as defined out the whole thing with no need
    side-effects , people could take a signal. Will likely be again to get more.
    Thanks

  5. 2018年5月26日04:07 | #5

    Hey! I just wanted to ask if you ever have any issues with
    hackers? My last blog (wordpress) was hacked and I ended up losing several weeks of hard
    work due to no data backup. Do you have any solutions to prevent hackers?

  6. 2018年5月26日05:04 | #6

    Amazing! Its genuinely awesome paragraph, I have got much clear idea concerning from this post.

  7. 2018年5月26日05:05 | #7

    Fine way of telling, and fastidious article to take
    facts about my presentation topic, which i am going to
    present in academy.

  8. 2018年5月26日05:48 | #8

    Have you ever thought about including a little bit more than just your articles?
    I mean, what you say is valuable and everything.
    Nevertheless just imagine if you added some great pictures or videos to give your posts more, “pop”!
    Your content is excellent but with images and videos, this website could definitely be one of the greatest in its field.
    Great blog!

  9. 2018年5月26日06:15 | #9

    If you want to obtain a good deal from this paragraph
    then you have to apply these techniques to your won web site.

  10. 2018年5月26日10:39 | #10

    Its not my first time to visit this web page, i am browsing this web
    site dailly and get nice facts from here all the time.

  11. 2018年5月26日11:27 | #11

    Its like you read my mind! You appear to know so much about this, like you wrote the book in it or something.
    I think that you could do with a few pics to drive the message home a little bit, but instead of that,
    this is great blog. A great read. I will certainly be back.

  12. 2018年5月26日13:44 | #12

    It’s in point of fact a nice and useful piece of info.
    I am happy that you shared this helpful info with us.

    Please keep us informed like this. Thank you for sharing.

  13. 2018年5月26日15:06 | #13

    Howdy just wanted to give you a quick heads up.
    The text in your content seem to be running off the screen in Ie.

    I’m not sure if this is a format issue or something to do with internet browser
    compatibility but I thought I’d post to let you know.
    The style and design look great though! Hope you get the issue fixed soon. Many thanks

  14. 2018年5月26日16:09 | #14

    Everything is very open with a very clear explanation of the issues.
    It was definitely informative. Your site is useful. Thank you for sharing!

  15. 2018年5月26日20:47 | #15

    I every time used to read article in news papers but now as I am a user of net therefore from now I am using net
    for content, thanks to web.

  16. 2018年5月29日03:19 | #16

    keep getting viagra emails yahoo
    viagra without a doctors prescription
    using viagra levitra together

  17. 2018年5月29日05:14 | #17

    What i do not understood is actually how you’re
    no longer actually a lot more neatly-appreciated than you
    might be right now. You’re very intelligent. You recognize therefore significantly with regards
    to this subject, produced me in my opinion believe it from numerous
    various angles. Its like women and men don’t seem to be
    interested unless it is one thing to do with Lady gaga! Your individual stuffs great.
    At all times maintain it up!

  18. 2018年6月1日01:54 | #18

    smettere di fumare

  19. 2018年6月1日04:21 | #19

    What’s up it’s me, I am also visiting this web page
    on a regular basis, this site is in fact fastidious and the people are genuinely sharing pleasant thoughts.

  20. 2018年6月1日04:43 | #20

    Saved as a favorite, I really like your website!

  21. 2018年6月1日14:51 | #21

    When some one searches for his vital thing, thus he/she wants to be available that in detail, so that thing is maintained over here.

  22. 2018年6月2日01:12 | #22

    If you would like to grow your familiarity only keep visiting this website
    and be updated with the newest information posted here.

  23. 2018年6月2日15:39 | #23

    Howdy just wanted to give you a quick heads up and let you
    know a few of the pictures aren’t loading correctly.
    I’m not sure why but I think its a linking issue.

    I’ve tried it in two different internet browsers and both
    show the same results.

  24. 2018年6月3日15:27 | #24

    I am truly glad to glance at this webpage posts which carries plenty of helpful information, thanks for providing these kinds of
    statistics.

  25. 2018年6月4日00:57 | #25

    Hey! I’m at work browsing your blog from my new iphone 3gs!
    Just wanted to say I love reading your blog and look forward to all your posts!
    Keep up the outstanding work!

  26. 2018年6月4日16:11 | #26

    each time i used to read smaller content which as well clear their motive, and
    that is also happening with this article which I am reading at this time.

  27. 2018年6月7日09:02 | #27

    Very nice post. I just stumbled upon your weblog and wished to say that I have
    really enjoyed browsing your blog posts. After all I’ll be subscribing to your feed and I hope you write again soon!

  28. 2018年6月7日16:01 | #28

    Hello, i believe that i saw you visited my website so i got here to
    return the prefer?.I’m trying to to find things to improve my web
    site!I suppose its good enough to make use of some
    of your ideas!!

  29. 2018年6月8日16:57 | #29

    Hi there to all, for the reason that I am really keen of reading this web site’s post to be updated daily.

    It carries fastidious material.

  30. 2018年6月8日21:52 | #30

    Very nice write-up. I absolutely appreciate this site. Continue the good work!

  31. 2018年6月9日00:11 | #31

    Excellent weblog here! Additionally your website a lot up fast!
    What host are you using? Can I get your affiliate hyperlink to
    your host? I want my website loaded up as fast as yours lol

  32. 2018年6月9日05:23 | #32

    Wonderful goods from you, man. I’ve understand
    your stuff previous to and you are just extremely fantastic.
    I really like what you have acquired here, really
    like what you’re saying and the way in which you say it.
    You make it entertaining and you still care for to keep
    it wise. I can’t wait to read far more from you. This is really a
    terrific website.

  33. 2018年6月9日10:47 | #33

    foods that contain polyphenols how to heal leaky gut what are lectins in foods [url=https://probiotics.us.org]how to get rid of belly bloat[/url]

  34. 2018年6月9日13:35 | #34

    Appreciate this post. Let me try it out.

  35. 2018年6月9日15:02 | #35

    Appreciating the dedication you put into your site and in depth information you present.

    It’s awesome to come across a blog every once in a while
    that isn’t the same out of date rehashed material.
    Fantastic read! I’ve saved your site and I’m adding your RSS feeds to my
    Google account.

  36. 2018年6月10日10:28 | #36

    Wow that was strange. I just wrote an extremely
    long comment but after I clicked submit my
    comment didn’t appear. Grrrr… well I’m not writing all
    that over again. Regardless, just wanted to say superb blog!

  37. 2018年6月11日04:31 | #37

    If some one needs expert view concerning blogging then i advise him/her to visit this weblog, Keep up the nice
    work.

  38. 2018年6月12日00:39 | #38

    This design is wicked! You obviously know how to keep a
    reader amused. Between your wit and your videos, I was almost moved to start my own blog (well,
    almost…HaHa!) Fantastic job. I really loved what you had to say,
    and more than that, how you presented it. Too cool!

  39. 2018年6月12日17:42 | #39

    Excellent post. Keep posting such kind of information on your blog.
    Im really impressed by your blog.
    Hi there, You have performed a fantastic job. I will
    definitely digg it and personally suggest to my friends.

    I am sure they will be benefited from this web site.

  40. 2018年6月12日20:52 | #40

    You should take part in a contest for one of the finest blogs on the internet.
    I am going to highly recommend this website!

  41. 2018年6月12日22:10 | #41

    I know this if off topic but I’m looking into starting my
    own blog and was wondering what all is required to get setup?
    I’m assuming having a blog like yours would cost a pretty penny?
    I’m not very internet savvy so I’m not 100% positive.
    Any suggestions or advice would be greatly appreciated.

    Appreciate it

  42. 2018年7月4日22:48 | #42

    Where do I order https://www.ning.com/?p=13662 where to buy in singapore.

  43. 2018年7月5日05:22 | #43

    buy online uk cheap https://www.ning.com/?p=6396 get cheap.

  44. 2018年7月16日18:58 | #44

    Most cleaners will embody display screen washing in the bid.

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