首页 > 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. 2017年11月1日04:16 | #1

    Awesome blog! Is your theme custom made or did you download it from
    somewhere? A theme like yours with a few simple adjustements would really make my blog stand out.

    Please let me know where you got your theme. Thanks

  2. 2017年11月1日15:19 | #2

    Why people still make use of to read news papers when in this technological globe all is
    existing on net?

  3. 2017年11月1日15:44 | #3

    Its like you read my mind! You appear to grasp a lot about this, like you wrote the
    e-book in it or something. I feel that you just could do with a
    few percent to force the message house a bit, but instead of
    that, this is great blog. A fantastic read. I’ll certainly be back.

  4. 2017年11月2日04:01 | #4

    Hi, I do believe this is an excellent blog. I stumbledupon it
    ;) I am going to return once again since I book-marked it.
    Money and freedom is the greatest way to change, may you be rich and continue to
    guide other people.

  5. 2017年11月2日04:16 | #5

    This web site certainly has all the information and facts I needed
    concerning this subject and didn’t know who to ask.

  6. 2017年11月2日09:24 | #6

    cialis generic to canada
    online pharmacy canada
    online drugs
    [url=http://callelasgardenias.com/index.php?option=com_k2&view=itemlist&task=user&id=1180446]canada drug stores[/url]

  7. 2017年11月2日15:54 | #7

    I have read so many articles or reviews regarding the blogger lovers however this
    article is genuinely a nice piece of writing, keep
    it up.

  8. 2017年11月3日02:31 | #8

    prescription drugs canada
    best online pharmacies
    canadian pharmaceuticals
    [url=http://immensewise.com/story.php?title=drug-store]best canadian pharcharmy online[/url]

  9. 2017年11月3日02:31 | #9

    1000g Of Amoxicillin Used For Stds Non Prescription Dog Amoxicillin Antibiotics Overnight Shipping Usa cialis price Cheap Generic Bentyl Need In Internet Cafergot Tablets No Rx

  10. 2017年11月3日16:43 | #10

    alternative viagra
    buy cheap generic viagra
    viagra online pharmacy
    [url=http://medsildenafilusa.com/]buy viagra online at[/url]
    what does viagra do

  11. 2017年11月4日14:55 | #11

    I visited various websites but the audio quality for audio songs
    present at this web page is genuinely excellent.

  12. 2017年11月5日17:09 | #12

    Hey There. I discovered your blog using msn. This is a very
    neatly written article. I will make sure to bookmark it and return to learn more
    of your helpful information. Thanks for the post.
    I’ll certainly comeback.

  13. 2017年11月8日14:08 | #13

    Asking questions are truly fastidious thing if you are not understanding anything completely, except this paragraph gives nice understanding even.

  14. 2017年11月11日18:48 | #14

    Definitely believe that which you stated.
    Your favorite justification appeared to be on the web the easiest thing to be
    aware of. I say to you, I definitely get annoyed while
    people consider worries that they just don’t know about.
    You managed to hit the nail upon the top as well
    as defined out the whole thing without having side effect ,
    people could take a signal. Will probably be back to get more.
    Thanks

  15. 2017年11月12日03:32 | #15

    I’ve been browsing on-line greater than 3 hours nowadays,
    yet I by no means discovered any interesting article like
    yours. It is pretty worth enough for me. In my opinion, if
    all site owners and bloggers made just right content as you did, the internet will probably be much more useful than ever before.

  16. 2017年11月12日05:12 | #16

    Generally I do not read article on blogs, but I would like
    to say that this write-up very forced me to check out and do
    it! Your writing style has been amazed me. Thanks, very great article.

  17. 2017年11月12日14:13 | #17

    Very soon this web site will be famous among all blogging viewers, due to it’s good articles

  18. 2017年11月12日20:29 | #18

    That is really fascinating, You are an excessively skilled blogger.
    I have joined your feed and look ahead to looking for more of your great post.

    Additionally, I have shared your site in my social networks

  19. 2017年11月12日20:43 | #19

    Today, I went to the beachfront with my children.
    I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to
    her ear and screamed. There was a hermit crab
    inside and it pinched her ear. She never wants to go back!

    LoL I know this is entirely off topic but I had to tell someone!

  20. 2017年11月13日00:28 | #20

    WOW just what I was looking for. Came here by searching for
    hello

  21. 2017年11月13日03:18 | #21

    Wow, this piece of writing is nice, my sister is analyzing
    these things, thus I am going to inform her.

  22. 2017年11月13日05:26 | #22

    Be aware that words three surprising key operating officials?

  23. 2017年11月13日11:14 | #23

    Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your weblog?
    My blog site is in the very same niche as yours and my visitors
    would definitely benefit from some of the information you
    present here. Please let me know if this okay with you.
    Thanks a lot!

  24. 2017年11月13日13:18 | #24

    I’ve been surfing on-line greater than 3 hours today, but I never discovered
    any attention-grabbing article like yours. It is beautiful value enough for me.
    Personally, if all site owners and bloggers made excellent content material as you probably did,
    the net will probably be much more helpful than ever before.

  25. 2017年11月13日13:31 | #25

    Hi there would you mind stating which blog platform you’re using?
    I’m planning to start my own blog soon but I’m having a difficult
    time selecting between BlogEngine/Wordpress/B2evolution and Drupal.
    The reason I ask is because your layout seems different then most
    blogs and I’m looking for something completely unique.
    P.S My apologies for being off-topic but I had to ask!

  26. 2017年11月14日05:36 | #26

    Do you possess moving patio and garden entrance in your property area?

  27. 2017年11月17日09:51 | #27

    Cialis Acquisto Farmacia Viagra Vergleich Cialis Levitra viagra Zyvox Keflex Mrsa Levitra Integratore Shipped Ups Dutasteride Free Doctor Consultation

  28. 2017年11月17日13:35 | #28

    Orquitis Propecia Propecia Online Australia viagra online prescription Azithreomycin Canadian Pharmacy On Line Macrobid Amoxicillin Maculopapular Virus

  29. 2017年11月17日20:37 | #29

    viagra prescription free viagras coupons
    get viagra
    cheapest viagra [url=http://sildenafil-citrate-us.com/]buy viagra online without prescription[/url]

  30. 2017年11月20日18:51 | #30

    viagras patent
    viagra uk
    what happens if a girl takes viagra
    [url=http://erectionhelpusa.com/]free viagra samples[/url]

    natural viagra

  31. 2017年11月24日05:55 | #31

    viagra online pharmacy
    viagra without prescription
    viagra from india
    [url=http://1stcanadapharm.com/viagra-sample/]viagra online pharmacy[/url]
    canadian viagra

  32. 2017年11月24日07:22 | #32

    aarp hartford auto insurance
    universal insurance
    auto insurance quotes california
    [url=http://autoinsurbest.com/]insurance card[/url]
    maif

  33. 2017年11月24日07:23 | #33

    generic cialis by mail
    cialis over the counter at walmart
    online no prescription cialis
    [url=http://cialispillsedweb.com/]cialis drug[/url]
    buy medication without an rx

  34. 2017年11月29日13:58 | #34

    low car insurance rates
    direct line insurance
    max insurance
    [url=http://carinsuranceflo.com/]florida car insurance[/url]
    auto owners ins

  35. 2017年11月30日15:31 | #35

    Priligy Dapoxetina Ricetta Propecia Ejaculation Cialis viagra Osu Levitra En France

  36. 2017年12月5日16:54 | #36

    Really when someone doesn’t understand then its up to other users that they will help, so here it happens.

  37. 2017年12月7日07:31 | #37

    teenagers car insurance
    car insurance quotes aaa
    car insurance scams car insurance in oregon
    [url=http://autocarins2018.com/maif-auto-insurance/]prices for car insurance[/url]

  38. 2017年12月8日00:12 | #38

    best price on cialis
    calias canda
    canadian cialis pharmacy
    [url=http://edpharmacybest.com/]cialis generic best price[/url]
    cialis 5mg canada

  39. 2017年12月8日06:07 | #39

    viagra wholesale

    viagra free samples

    viagra patent expiration date

    [url=http://1stmedsusa.com/]buying viagra online[/url]

    100mg viagra

  40. 2017年12月8日09:20 | #40

    indian pharma
    canadian pharmaceuticals
    buy drugs without a prescription canada drug pharmacy
    [url=http://canadianpharmacyonline.us.com/]canada drug stores[/url]

    canadian pharmacies shipping to usa

  41. 2017年12月12日13:22 | #41

    cialis for sale
    cialis daily use
    tadalafil online buying cialis from canada
    [url=http://online20mg-cialis.net/]cialis coupon[/url]

  42. 2017年12月17日05:44 | #42

    cheap canadian meds cheap cialis in canada
    best treatments for ed viagra online from canada
    [url=http://besttrustpharmacy.com/]canada discount drugs[/url]

  43. 2017年12月24日09:03 | #43

    aarp auto insurance quote auto insurance san francisco ca cheap car insurance chicago [url=http://topcarinsurancerate.com/]cheapest auto insurance in ma[/url] maryland auto insurance fund

  44. 2017年12月24日20:44 | #44

    auto insurance for mexico bristol west car insurance usaa car insurance quote [url=http://3danarchy.com/]aaa rental car insurance coverage[/url] low cost car insurance

  45. 2017年12月24日21:18 | #45

    can you get viagra without prescription cialis price of cialis at walmart

    [url=http://pharmacyus24h.com/]mail order cialis[/url] celias pills

  46. 2017年12月29日06:34 | #46

    Saved as a favorite, I really like your website!

  47. 2018年1月5日10:28 | #47

    What i do not understood is actually how you’re now not actually much
    more neatly-favored than you might be now.
    You are so intelligent. You already know therefore significantly when it comes to this subject, made me individually consider it
    from numerous numerous angles. Its like women and men are not involved
    until it is one thing to do with Girl gaga!
    Your own stuffs nice. All the time take care of it up!

  48. 2018年1月7日06:51 | #48

    Hi Dear, are you actually visiting this website regularly, if so after that you will
    without doubt obtain pleasant knowledge.

  49. 2018年1月12日11:29 | #49

    I savour, result in I found just what I was looking
    for. You’ve ended my 4 day lengthy hunt! God Bless you man.
    Have a nice day. Bye

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