问题描述
限时送ChatGPT账号..我对设置 Socket.IO 服务器 + Rails Web 应用程序很感兴趣.然而,正如许多人所知,支持 WebSockets 的 Web 服务器并不多.到目前为止,这是我的 2 次尝试:
I'm interested in setting up a Socket.IO server + Rails web application. However, as many are aware, there are not many web servers that support WebSockets. Here have been my 2 attempts so far:
我尝试了 Nginx 模块路线.无法获得编译 + 配置的组合以使其完全正常工作.可能对我来说有些愚蠢.
I tried the Nginx-module route. Couldn't get the combinations of compilations + configurations to get this fully working. Probably something dumb on my part.
http://www.letseehere/reverse-proxy-web-sockets
我尝试使用 node-http-proxy 编写自己的 Web 服务器,但尽管阅读了所有教程,但我无法将其与 Socket.IO 完全集成.
I tried writing my own web server with node-http-proxy but I had trouble fully integrating this with Socket.IO, despite reading all the tutorials.
http://github/nodejitsu/node-http-proxy
我尝试使用 bouncy.js 编写自己的 Web 服务器,但速度非常慢.可能是我的代码,也可能是框架.我不知道.
I tried writing my own web server with bouncy.js but it's horribly slow. Could be my code, could be the framework. I have no idea.
http://github/substack/bouncy
这些是我尝试过的事情,我很好奇还有谁沿着这些路线走下去并最终取得了一些成果(当然,他们做了什么才能让它发挥作用).
These are the things I've tried, and I'm just curious who else has gone down these routes and finally got something work (and of course, what they did to get it working).
推荐答案
根据 alessioalex 的要求,这是我的配置文件.我删除了所有现有的评论,但添加了一些我自己认为不重要的评论.
As per alessioalex's request, here's my configuration file. I deleted all the existing comments but added a few that I, myself, would not have figured to be important.
然而,描述此配置的所有部分的作用超出了本文的范围,但您可能会在 HAProxy 网站上找到必要的文档.
However, describing what all the parts of this config does is out of the scope of this post, but you can likely find the necessary documentation on the HAProxy website.
global
maxconn 4096
pidfile /var/run/haproxy.pid
defaults
mode http
frontend all
bind 0.0.0.0:80
mode tcp
maxconn 200000
timeout client 86400000
default_backend www_backend
# Any URL beginning with socket.io will be flagged as 'is_websocket'
acl is_websocket path_beg /socket.io
acl is_websocket hdr(Upgrade) -i WebSocket
acl is_websocket hdr_beg(Host) -i ws
# The connection to use if 'is_websocket' is flagged
use_backend socket_backend_http if is_websocket
tcp-request inspect-delay 500ms
tcp-request content accept if HTTP
backend www_backend
option httplog
option httpclose
balance roundrobin
option forwardfor
timeout server 30000
timeout connect 4000
server thin1 localhost:4001 weight 1 maxconn 1024 check
server thin2 localhost:4002 weight 1 maxconn 1024 check
server thin3 localhost:4003 weight 1 maxconn 1024 check
backend socket_backend_http
mode http
option httplog
option http-server-close
option forceclose
no option httpclose
balance roundrobin
option forwardfor
timeout queue 5000
timeout server 86400000
timeout connect 86400000
timeout check 1s
server socket1 localhost:5001 weight 1 maxconn 1024 check
这篇关于WebSocket/Socket.IO 服务器的一个很好的解决方案(我尝试过 Nginx、Node 等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论