问题标签 [haproxy]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
2050 浏览

varnish - 多个带有 haproxy 的清漆服务器

我们计划在我们的基础设施中添加第二台清漆服务器。

平衡两台服务器的流量的更好方法是什么?我认为我们可以在两台服务器前面使用 haproxy,但是如何配置它来负载平衡 2 varnish 之间的流量呢?理想的解决方案是,如果一种清漆出现故障,所有流量都会流向另一种。

编辑:理想的行为是主动/主动配置,每个都有 50% 的负载,如果一个发生故障,haproxy 会向另一个发送 100% 的负载。

0 投票
2 回答
3103 浏览

node.js - 通过 NGINX 的 Node.JS、HAproxy 和 Socket.IO,应用程序位于子目录中

我已经尝试了几个小时,并阅读了这个网站和互联网所提供的内容。我似乎无法让 Socket.IO 在这里正常工作。我知道默认情况下 nginx 不能处理 Socket.IO 但是,HAproxy 可以。我希望 nginx 通过 unix 套接字为 Node 应用程序提供服务,并且效果很好。每个都有一个由 nginx 设置的子目录位置,但是,现在我需要 Socket.IO 用于最后一个应用程序,此时我无法配置。

我有最新的 socket.io、HAproxy 1.4.8 和 nginx 1.2.1。运行 ubuntu。

所以重申一下,我需要通过 nginx 让 socket.io 工作到子目录中的节点应用程序,例如:localhost/app/。

如果我能提供其他任何东西,现在就让我来吧!

0 投票
3 回答
53969 浏览

proxy - haproxy 匹配 use_backend 中的各种条件

我正在尝试在一个后端匹配各种条件,如下所示:

但是,我怎样才能把这个“和”放在两条规则之间呢?

0 投票
2 回答
3834 浏览

node.js - nginx、node.js 和 socket.io - 有工作婚姻吗?

nginx是杀手级静态文件服务器。

node.js本例所示,它可以提供服务,但方式有限。

nginx显然无法代理websockets

我发现唯一可行的方法是根据本文使用HAProxy前端- 但它是从 2011 年 10 月 6 日开始的。

必须是一个常见问题,但我没有找到一个非常常见的解决方案。


解决方案

(有关完整的解决方案和详细信息,请参阅https://github.com/bangkok-maco/barebone-node )

ip 测试架构:

  • 127.0.0.12 - www.chat.nit - 公共,在 /etc/hosts 和 haproxy
  • 127.0.1.12 - 内部 nginx 网络服务器
  • 127.0.2.12 - 内部聊天服务 node.js socket.io

/etc/haproxy/haproxy.cfg:

/etc/nginx/sites-enabled/www.chat.nit

聊天(node.js):server.js

聊天:client.html

笔记:

  1. 将socket.io客户端js链接到scripts/目录

    /.../scripts$ ln -s ../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io

  2. /etc/default/haproxy (与文本相反,必须设置为工作

    启用=1

  3. 这个版本的 haproxy 没有记录。找到kvz关于如何rsyslogd通过127.0.0.1使用的文章,但无法让它飞起来。

  4. 该解决方案有效-可以确定不是系统管理员质量。(增强功能非常受欢迎。)

0 投票
2 回答
5004 浏览

amazon-ec2 - Haproxy 负载均衡器,EC2,编写我自己的可用性脚本

我一直在研究高可用性解决方案,例如 heartbeat,以及当 haproxy 负载均衡器出现故障时进行故障转移的 keepalived。我意识到,虽然我们想要高可用性,但在任何时候运行 2 个负载均衡器实例的支出范围内,这并不是真正的要求,以便我们获得即时故障转移(尤其是一磅在我们的设置中将是多余的)。

如果当前负载均衡器已停止工作,我的替代解决方案是从 AMI 启动一个新的负载均衡器 EC2 实例,并将其与我们的域名指向的弹性 IP 相关联。这应该确保停机时间限制在启动新实例和关联弹性 ip 所需的时间,鉴于我们目前的情况,这似乎是高可用性的合理成本有效的解决方案,特别是因为我们可以轻松地进行多 av区。我希望使用以下步骤来做到这一点:

  1. 准备负载均衡器的 AMI
  2. 启动一个充当负载均衡器的 ec2 实例并为其分配弹性 IP
  3. 让微型服务器定期 ping 当前的负载均衡器(无论如何,我们总是有一个额外的微型服务器在运行)
  4. 如果 ping 超时,请使用负载均衡器 AMI 启动新的 EC2 实例
  5. 将弹性 ip 关联到新实例
  6. 关闭旧的负载均衡器实例
  7. 对新实例重复步骤 3

我知道如何在我的脚本中运行命令来启动和关闭 EC2 实例、将弹性 IP 地址关联到实例以及 ping 服务器。

我的问题是这里合适的 ping 是什么?定期进行标准 ping 就足够了,什么是好的间隔?或者这是一种相当简单的方法,并且我应该进行更智能的健康检查?

另外,如果有人预见到这种方法有任何问题,请随时发表评论

0 投票
1 回答
2162 浏览

linux - haproxy - 将当前端口添加到标头

我想将当前端口号添加到标题中。我试过了:

但它添加dst_port而不是数字。

有没有办法添加变量 dst_port 做标题?

0 投票
1 回答
424 浏览

node.js - 服务 websocket 的 socket.io 是否需要物理上位于端口 80 上?

使用node.jssocket.io服务websockets

是否socket.io需要监听端口 80 - 的真实端口websockets,或者它可以代理到服务器上的不同端口,例如端口 8011?

浏览器使用websockets80/http 进行通信。服务器上haproxy 重定向websocketsnode.js.

权利haproxy指向127.0.4.11:80。这工作正常,但这需要sudo运行node.js

宁愿重定向到localhost:8011,但不知道是否socket.io需要实际在端口 80 上才能websockets正确支持。

0 投票
1 回答
209 浏览

web-services - 用 Coffeescript 编写的 Node JS 服务器可以工作,但 JS 版本不行

我有两个节点服务器作为我的后端服务器,前端有一个 haproxy 服务器来循环传入 HTTP 请求。带有咖啡的服务器工作正常,但是带有用 JS 编写的已编译咖啡脚本版本的服务器在运行几个小时后就崩溃了。咖啡代码和编译后的 JS 代码看起来一模一样。当 JS 版本崩溃时,它开始发送 502 响应。这些服务器每天处理大约 500 万个请求(合计)。有人见过这个问题吗?

0 投票
1 回答
1030 浏览

haproxy - 如何使用 HAProxy 维护静态 URL

我正在使用带有两个不同节点的 Haproxy,这些节点具有“地理上分散”的不同机器

  • 具有 dns = http1.example.com 的负载均衡器
  • 具有 dns = http2.example.com 的负载均衡器两个

该服务正在使用原始主机名--haproxy侦听 DNS主站点

我的问题是如何维护静态 URL?即它不能显示后端服务器域或IP,我只想显示原始主机名。

0 投票
1 回答
1491 浏览

apache - firefox url rewriting mysteriously, but not other browsers

I have a bizarre problem that only (so far) manifests itself in Firefox, where it rewrites the URL to a different domain (also hosted by us). The rewrite however does not occur in Safari or Chrome (I'm testing from a MacBook Pro).

My setup is this: The loadbalancer running HAProxy listening on 80 an internally 8080 and Apache listening on 443. Traffic on 80 is passed to the backend, traffic from Apache is SSL decrypted then sent to localhost:8080 and then passed to the backend's port 8443. On the backend, any traffic from 80 is considered non-SSL, but on 8443 is considered decrypted SSL. Backend servers are running Apache.

If I go to https://www.sslexample.com/ (henceforth SSL_DOMAIN) from any browser on an SSL site, everything behaves as it should. It hits the Apache SSL accelerator, is decrypted, passed to the proxy, then sent to the backend. If I go to http://www.nonsslexample.com/ (henceforth NONSSL_DOMAIN), again, everything behaves as expected for a non-SSL site, it hits the proxy, then the backend, and non-SSL traffic is served as expected.

Here's where things get weird. If I go to SSL_DOMAIN via http, what's supposed to happen is that I'm redirected to https. For one of our mixed SSL/non-SSL domains, this works as expected from all browsers. BUT on Firefox (and sometimes on Safari for my colleague and never on Chrome) if I go to SSL_DOMAIN via http, the first thing that happens is that the URL is immediately rewritten to the NONSSL_DOMAIN and I'm redirected to the completely different domain.

Huh?

Looking at the logs on the LB, Chrome and Safari behave as they should--hit the lb on port 80--but Firefox never hits the loadbalancer with the SSL_DOMAIN on port 80. But the time to LB sees it, it's already been rewritten.

I installed the Tamper Data plugin on Firefox, and the results confused me more. The initial correct URL header never receives a reply header. It's immediately replaced with the incorrect one. And things carry on as if I had intended the non-SSL URL.

I looked in my /etc/hosts file (since this is in testing and we're overriding these domains), and everything looks correct.

If you have ever encountered a problem like this before, I'd be very grateful for tips on how to debug it.