如何用Lighttpd安装mod_websocket?

时间:2014-03-25 10:36:41

标签: node.js websocket lighttpd socket.io

我想让Lighttpd与websocket(Socket.IO)一起使用,看来唯一的方法就是安装一个额外的模块:mod_websocket。我跟着these steps,但我认为我没有得到正确的/path/to/lighttpd_top_srcdir。当我/usr/lib/lighttpd编辑时,我使用了ls,因为我看到了这里的所有模块。 显然,我需要重新安装Lighttpd,对吗?

到目前为止,我得到了

copy mod_websocket files into /usr/lib/lighttpd
cp src/mod_websocket*.{h,c} /usr/lib/lighttpd/src
cp: target « /usr/lib/lighttpd/src » is not a directory

我需要这样做,因为我在尝试使用websockets时遇到的错误如下:WebSocket connection to 'ws://<myURL>/socket.io/1/websocket/agXkznae1gmlDTutzJyk' failed: Unrecognized frame opcode: 5(我使用谷歌浏览器v33.0.1750.154)。

还有另一种方法可以让websockets与Lighttpd配合使用,还是需要更改网络服务器?

非常感谢!

1 个答案:

答案 0 :(得分:0)

我解决了我的问题!

我使用了this question

中指定的HAProxy而不是Lighttpd mod_proxy

这是我的conf文件(根据您的配置修改<...>):

# this config needs haproxy-1.1.28 or haproxy-1.2.1

global
  log  127.0.0.1  local0
  log  127.0.0.1  local1 notice
  maxconn  4096
  uid  99
  gid  99
  daemon

defaults
  log   global
  mode  http
  option  httplog
  option  dontlognull
  retries  3
  option http-use-proxy-header
  option  redispatch
  option  http-server-close
  maxconn  2000
  contimeout  5000
  clitimeout  50000
  srvtimeout  50000

frontend public
  bind *:80
  acl is_example hdr_end(host) -i <URL.toyourwebsite.com>
  acl is_websocket hdr(Upgrade) -i WebSocket
  acl is_websocket path_beg -i /websockets
  use_backend ws if is_websocket is_example
  default_backend www

backend ws
    balance roundrobin
    option forwardfor # This sets X-Forwarded-For
    timeout queue 5000
    timeout server 86400000
    timeout connect 86400000
    server apiserver localhost:<PORT> weight 1 maxconn 1024 check

我让Lighttpd听了8080端口(否则HAProxy就不会启动)。