Qinyng 2015-08-23 13:56 采纳率: 0%
浏览 3484

HaProxy设置TCP Mode却无法分发给后面的服务器

我使用HaProxy作为负载平衡,版本为1.5.14
这是haproxy.cfg文件配置:
global

log 127.0.0.1 local2 debug
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
debug

default
mode tcp
retries 2
option redispatch
option abortonclose
maxconn 4096
timeout connect 5000ms
timeout client 30000ms
timeout server 30000ms
#timeout check 2000
log 127.0.0.1 local0 debug

listen app1
log 127.0.0.1 local2 debug
bind 0.0.0.0:5000
mode tcp
server s1 127.0.0.1:5001 check
server s2 127.0.0.1:5002 check

后面的服务器我用node.js写的:
var net = require('net');

var server = net.createServer(function(sv_c){
    sv_c.on('error',function(err){
        console.log(err);
    });

    sv_c.on('data',function(data){
        console.log(data);
        sv_c.write("ok");
    })

    sv_c.on('end',function(){
        console.log('close socket');
    })

    console.log(sv_c.remoteAddress);
    console.log(sv_c.remotePort);
    console.log(sv_c.localAddress);
    console.log(sv_c.localPort);

}).listen(5001);

请求程序我也是node.js写的:
var net = require('net');

var client = new net.Socket();
client.on('error',function(err){
    console.log(err);
});

client.connect(5000,'127.0.0.1',function(){
    console.log('connection');
    client.write("request");
    client.on('data',function(data){
        console.log(data+"end");
        client.end();
    })
})

我的服务器端没有收到连接,请求端返回了一段网页:
HTTP/1.0 400 Bad request
Cache-Control: no-cache
Connection: close
Content-Type: text/html

400 Bad request


Your browser sent an invalid request.

我已经设置为tcp mode了呀,还有那些地方做错了吗?

  • 写回答

1条回答 默认 最新

  • devmiao 2015-08-23 14:27
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog