Haproxy URL 路由不正确
Haproxy URL route not work corrent
我有一个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]
我发现问题了,这里不能用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
它工作正常。
我有一个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]
我发现问题了,这里不能用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
它工作正常。