ngx-http-split-clients模塊基于一些特定條件分開客戶端連接,(例如ip地址,請求頭,cookies等)
示例配置:
http { split-clients "${remote-addr}AAA" $variant { 0.5% .one; 2.0% .two; - ""; } server { location / { index index${variant}.html;
可以使用$cookie-…作為來源來分離請求,來源字符串使用CRC32進行哈希計算并且哈希百分比將作為來源的值。
指令
split-clients
語法:split-clients $variable { … }
默認值:none
使用字段:http
發現模塊官網wiki給的上面的示例配置代碼有幾點問題,我編譯安裝后,按照wiki的方法配置nginx.conf 報錯。
我實際的代碼是:
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.htmlecho "two" >index.two.htmlecho "eric" >index.eric.htmlecho "thr" >index.thr.html
配置差別:
wiki : split-clients eric:split_clientswiki : remote-addr eric: remote_addrwiki : - ""; eric: * "";關于這些錯誤的發現是因為 nginx 有 remote_addr 變量 并沒有 remote-addr ·我就順藤摸瓜·
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" "$variant"';以便于我們測試結果。
http { split_clients "${remote_addr}AAA" $variant { 0.5% .one; 2% .two; * ""; }
代碼如下:
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"
新聞熱點
疑難解答