NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
holinhot
V2EX  ›  NGINX

nginx 反相代理这么设置一个概率跳转至另外一个域名

  •  
  •   holinhot · May 16, 2015 · 5082 views
    This topic created in 4063 days ago, the information mentioned may be changed or developed.

    Nginx 反相代理这么设置一个概率跳转至另外一个域名
    1.com 反向代理 2.com 设置一个 20%概率跳转至 3.com 这么实现

    20 replies    2015-05-18 20:54:59 +08:00
    Showfom
        1
    Showfom  
    PRO
       May 16, 2015 via iPhone
    cache key一样了
    holinhot
        2
    holinhot  
    OP
       May 16, 2015
    @Showfom 有没有智能的
    liuhaotian
        3
    liuhaotian  
       May 16, 2015
    你需要一个 nginx_lua 模块,可以选择在 rewrite_by_lua 进行控制
    holinhot
        4
    holinhot  
    OP
       May 16, 2015
    @liuhaotian 有相关文档吗没用过这个
    liuhaotian
        5
    liuhaotian  
       May 16, 2015
    holinhot
        6
    holinhot  
    OP
       May 16, 2015
    @liuhaotian

    location / {
    rewrite_by_lua '
    local res = ngx.location.capture("/check-spam")
    if res.body == "spam" then
    ngx.redirect("/terms-of-use.html")
    end
    '; fastcgi_pass ...;
    }

    这个概率应该怎么写呢
    liuhaotian
        7
    liuhaotian  
       May 16, 2015
    nginx lua 支持 random 随机函数
    random=math.random()
    你可以针对这个搜索
    holinhot
        8
    holinhot  
    OP
       May 16, 2015
    @liuhaotian if时间秒来设置概率?
    holinhot
        9
    holinhot  
    OP
       May 16, 2015
    @liuhaotian ok我找一下
    ryd994
        10
    ryd994  
       May 17, 2015 via Android
    Nginx 有 AB test模块啊……
    jqw1992
        11
    jqw1992  
       May 17, 2015
    这是要做什么啊
    holinhot
        12
    holinhot  
    OP
       May 17, 2015
    @jqw1992
    @ryd994
    @holinhot
    @holinhot
    @liuhaotian
    @Showfom

    能不能设置10个轮循 然后8个是代理至源网站 2个到其他服务器,轮到其他服务器这2个其他服务器的就跳转。 不知道能不能对同一个ip源进行轮循
    liuhaotian
        13
    liuhaotian  
       May 17, 2015 via iPhone
    这个明显的在你的原服务器进行处理就可以了,为什么要代理服务器处理呢… 另外lua应当是可以的
    jqw1992
        14
    jqw1992  
       May 17, 2015
    @holinhot 真不知道 你想做什么 。。。这个写个程序 就可以啊
    holinhot
        15
    holinhot  
    OP
       May 17, 2015
    @jqw1992 就是我想反代某个网站 想设置一个概率转到我自己的网站
    holinhot
        16
    holinhot  
    OP
       May 17, 2015
    @jqw1992
    我看nginx-http-footer-filter 用这个在页面加几行代码来实现概率跳转可以吗?
    holinhot
        18
    holinhot  
    OP
       May 18, 2015
    @ryd994 这个正是我要的
    holinhot
        19
    holinhot  
    OP
       May 18, 2015
    @ryd994 还要增加一个同一ip地址固定时间内只跳转1次
    ryd994
        20
    ryd994  
       May 18, 2015 via Android
    @holinhot 这个比较麻烦
    Nginx为了性能,基本上是无状态的
    也许可以用cookies,但是Nginx判断cookie也麻烦
    或者可以加个cgi后端,返回个跳转给Nginx不复杂,比较恶心
    最简单应该是带尾巴,不过处理不好的话上游会发现。除了这个没有其他问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3126 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 14:14 · PVG 22:14 · LAX 07:14 · JFK 10:14
    ♥ Do have faith in what you're doing.