【问题标题】:Haproxy URL route not work correntHaproxy URL 路由无法正常工作
【发布时间】:2015-01-28 15:31:28
【问题描述】:

我有一个API Web服务器,有两个版本的api并存,它们是通过url路径路由的,分别是/shine/v7和/shine/v8。

我是通过 haproxy 制作的,但是当我请求 /shine/v7/admin 时,它有时会转到shine_v8_backend,有时会转到shine_v7_backend,我不知道为什么会发生这种情况,有人可以帮助我吗?

这是我的 haproxy.conf

global
    log 127.0.0.1   local0
    log 127.0.0.1   local1 notice
    maxconn 4096
    daemon

defaults
    log     global
    option  http-server-close

frontend http *:5000
    mode tcp
    timeout client 86400000

    default_backend shine_v8_backend
    acl shine_v7    path_dir /shine/v7
    use_backend     shine_v7_backend    if shine_v7


backend shine_v8_backend
    mode tcp
    option httpclose
    balance roundrobin
    timeout server 86400000
    timeout connect 5000
    server host_0 127.0.0.1:5001

backend shine_v7_backend
    mode tcp
    option httpclose
    balance roundrobin
    timeout server 86400000
    timeout connect 5000
    server host_0 127.0.0.1:5002

我尝试多次请求/shine/v7/admin,有日志

$ sudo haproxy -f haproxy.conf -d
Available polling systems :
     kqueue : pref=300,  test result OK
       poll : pref=200,  test result OK
     select : pref=150,  test result FAILED
Total: 3 (2 usable), will use kqueue.
Using kqueue() as the polling mechanism.
00000000:http.accept(0004)=0006 from [127.0.0.1:55026]
00000000:shine_v7_backend.srvcls[0006:0007]
00000000:shine_v7_backend.clicls[0006:0007]
00000000:shine_v7_backend.closed[0006:0007]
00000001:http.accept(0004)=0006 from [127.0.0.1:55028]
00000001:shine_v8_backend.srvcls[0006:0007]
00000001:shine_v8_backend.clicls[0006:0007]
00000001:shine_v8_backend.closed[0006:0007]
00000002:http.accept(0004)=0006 from [127.0.0.1:55030]
00000002:shine_v7_backend.srvcls[0006:0007]
00000002:shine_v7_backend.clicls[0006:0007]
00000002:shine_v7_backend.closed[0006:0007]
00000003:http.accept(0004)=0006 from [127.0.0.1:55032]
00000003:shine_v8_backend.srvcls[0006:0007]
00000003:shine_v8_backend.clicls[0006:0007]
00000003:shine_v8_backend.closed[0006:0007]
00000004:http.accept(0004)=0006 from [127.0.0.1:55034]
00000004:shine_v7_backend.srvcls[0006:0007]
00000004:shine_v7_backend.clicls[0006:0007]
00000004:shine_v7_backend.closed[0006:0007]

【问题讨论】:

    标签: url-routing haproxy


    【解决方案1】:

    我找到了问题,这里不能使用tcp模式,必须使用http模式:(

    修复后,haproxy.conf 为

    global
        log 127.0.0.1   local0
        log 127.0.0.1   local1 notice
        maxconn 4096
        daemon
    
    defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        option  forwardfor
        option  http-server-close
    
    frontend http *:5000
        timeout client 86400000
    
        acl shine_v8    path_dir /shine/v8
        acl shine_v7    path_dir /shine/v7
    
        use_backend     shine_v8_backend    if shine_v8
        use_backend     shine_v7_backend    if shine_v7
    
    backend shine_v8_backend
        option httpclose
        balance roundrobin
        timeout server 86400000
        timeout connect 5000
        server host_0 127.0.0.1:5001
    
    backend shine_v7_backend
        option httpclose
        balance roundrobin
        timeout server 86400000
        timeout connect 5000
        server host_0 127.0.0.1:5002
    

    效果很好。

    【讨论】:

      猜你喜欢
      • 2012-07-28
      • 2016-10-17
      • 2012-01-29
      • 2016-11-26
      • 2014-12-05
      • 2018-01-17
      • 2017-10-15
      相关资源
      最近更新 更多