我一直在尝试测试一个如下所示的设置:
网站: Http获取请求-> Nginx -> HAProxy -> .Net应用程序
我把Nginx和HAProxy放在同一台Debian机器上。然而,HAProxy不断地返回“坏请求(无效主机)”。我已经确定HAProxy是错误的,它首先将请求直接从网站发送到.Net应用程序,这是可行的。让Nginx链接到.Net应用程序也是可行的。但是,当我尝试用HAProxy进行测试时,我开始得到错误。不管.Net应用程序是否实际运行在HAProxy之后,我总是会收到错误。
我试图发送的消息的一个例子是http://192.168.7.119:81/a:diff1。预期的答复是一个JPG图像。当发送到HAProxy (Apache,Nginx,应用程序)之外的任何东西时,这看起来都很好,但是HAProxy只是说“不好的请求”。奇怪的是,我在日志文件中没有看到任何错误。
下面是日志文件中的一个示例:
Feb 2 15:10:08 companyDebian haproxy[5566]: 192.168.7.114:51105 [02/Feb/2015:15:10:08.415] renderfarm renderfarm/renderA 0/0/0/1/1 400 212 - - ---- 1/1/0/1/0 0/0 "GET /a:diff1 HTTP/1.1"
Feb 2 15:10:08 companyDebian haproxy[5566]: 192.168.7.114:51105 [02/Feb/2015:15:10:08.417] renderfarm renderfarm/renderA 73/0/0/4/77 400 212 - - ---- 1/1/0/1/0 0/0 "GET /favicon.ico HTTP/1.1"我的配置文件如下所示:
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
daemon
# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private
# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL).
ssl-default-bind-ciphers kEECDH+aRSA+AES:kRSA+AES:+AES256:RC4-SHA:!kEDH:!LOW:!EXP:!MD5:!aNULL:!eNULL
ssl-default-bind-options no-sslv3
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
errorfile 400 /etc/haproxy/errors/400.http
errorfile 403 /etc/haproxy/errors/403.http
errorfile 408 /etc/haproxy/errors/408.http
errorfile 500 /etc/haproxy/errors/500.http
errorfile 502 /etc/haproxy/errors/502.http
errorfile 503 /etc/haproxy/errors/503.http
errorfile 504 /etc/haproxy/errors/504.http
listen renderfarm
bind 192.168.7.119:81
mode http
balance roundrobin
server renderA 192.168.7.114:40000 maxconn 1我之前没有使用HAProxy的经验,我正在使用它,因为它是推荐给我的。因此,我不知道我还能采取哪些其他步骤来解决这个问题。配置手册提到了您可以设置的各种选项,例如tune.bufsize和选项,但是这些选项没有任何效果。
注意:一旦安装成功,就可以添加更多运行应用程序的服务器。每个服务器一次只能处理一个请求。
发布于 2015-02-02 15:21:23
如果您想看到HAproxy运行的确切错误,可以使用socat连接到管理套接字。通过socat通过apt-get install socat安装,然后运行以下命令:
echo "show errors" | socat unix-connect:/run/haproxy/admin.sock stdio如果您在收到“坏请求”错误后正确运行该请求,则应该会准确地显示HAproxy不喜欢客户端发出的HTTP请求的内容。
注意:只有当您为
Unix Socket commands启用了HAProxy时,上述功能才能正常工作。您必须在global部分下添加一行配置才能启用此功能。全局统计socket /var/run/haproxy.sock模式600级管理正式文件
发布于 2015-02-02 16:04:47
尝试将HAProxy配置更改为TCP而不是HTTP可能是值得的。您将失去HTTP提供的一些高级负载平衡选项(为持久性设置cookies等),但您现在似乎没有使用它们。
下面是我与HAProxy一起使用的用于MySQL负载平衡的示例配置:
listen mysql-failover
bind 10.10.10.210:3306
mode tcp
option tcplog
option mysql-check user haproxy
server db1 10.10.10.13:3306 check fall 2 inter 1000
server backup 10.10.10.11:3306 check请注意,如果更改为TCP,您将无法访问内置的HTTP页面,您可以在单独的listen语句中定义该页面。例如:
listen stats
bind 10.10.10.200:80
mode http
stats enable
stats hide-version
stats uri /
option httpclose
stats auth username:passwordhttps://serverfault.com/questions/664332
复制相似问题