无法使用Lighttpd访问Raspberry Pi上的socket.io.js

自从昨天以来,我对Node.JS和Socket.IO完全陌生。

我尝试使Node.JS和Socket.IO在我的Raspberry Pi上工作,但似乎没有。 我无法访问<myip>:1337/socket.io/socket.io.js 我遵循这个教程,所以我的Lighttpd.conf文件看起来像这样:

 $HTTP["host"] == "<myURLtomywebsite>" { proxy.server = (" " => (( "host" => "<myIP>", "port" => 1337) ) ) 

我的server.js看起来像这样:

 var http = require('http'); httpServer = http.createServer(function(req, res) { res.end('Hello World!'); }); httpServer.listen(1337); var io = require('socket.io').listen(httpServer); var clients = 0; io.sockets.on('connection', function(socket) { ++clients; socket.on('disconnect', function(data) { --clients; io.sockets.emit('disusr', clients); }); io.sockets.emit('newusr', clients); }); 

我绑定到我的client.jsdisusrnewusr事件来显示连接的用户在一个div

一切看起来不错,我的localhost但在生产环境,我不能链接到我的socket.io.js文件在1337端口。 说实话,我甚至不知道要使用什么地址? (我的网站的URL附加:1337localhost ,我会创build一些其他地址?)

任何帮助将非常感激。 谢谢!

我解决了我的问题!

我把socket.io.js链接成这样: <script type="text/javascript" src="/socket.io/socket.io.js"></script>

我使用HAProxy而不是Lighttpd mod_proxy在这个问题中指定

这里是我的conf文件(根据你的configuration修改<...> ):

 # 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不会启动)。

提醒没有必要使用mod_proxy,因为它已知与websockets不兼容。 改用HAProxy。