Javascript Can';t使用Lighttpd[Node.js&;socket.io]访问Raspberry Pi上的socket.io.js
从昨天开始,我对Node.JS和Socket.IO就完全陌生了 我试图让Node.JS和Socket.IO在我的Raspberry Pi上工作,但似乎没有我无法访问Javascript Can';t使用Lighttpd[Node.js&;socket.io]访问Raspberry Pi上的socket.io.js,javascript,node.js,raspberry-pi,socket.io,lighty,Javascript,Node.js,Raspberry Pi,Socket.io,Lighty,从昨天开始,我对Node.JS和Socket.IO就完全陌生了 我试图让Node.JS和Socket.IO在我的Raspberry Pi上工作,但似乎没有我无法访问:1337/socket.io/socket.io.js 我遵循了以下步骤,因此我的Lighttpd.conf文件如下所示: $HTTP["host"] == "<myURLtomywebsite>" { proxy.server = (" " => (( "host" => "<
:1337/socket.io/socket.io.js
我遵循了以下步骤,因此我的Lighttpd.conf文件如下所示:
$HTTP["host"] == "<myURLtomywebsite>" {
proxy.server = (" " => ((
"host" => "<myIP>",
"port" => 1337)
)
)
我绑定到我的client.js
中的disusr
和newusr
事件,以显示div
中连接的用户数
在我的localhost
上看起来一切正常,但在生产环境中,我无法链接到1337
端口上的socket.io.js
文件。老实说,我甚至不知道该用什么地址?(我的网站的URL附加了:1337
,localhost
,一些我应该创建的其他地址?)
任何帮助都将不胜感激。谢谢 我解决了我的问题
我像这样链接了socket.io.js
:
我使用了HAProxy,而不是中指定的Lighttpd mod_代理
这是我的conf文件(根据您的配置修改
):
#此配置需要haproxy-1.1.28或haproxy-1.2.1
全球的
日志127.0.0.1 local0
日志127.0.0.1本地1通知
maxconn 4096
uid 99
gid 99
守护进程
默认值
日志全局
模式http
选项httplog
选项dontlognull
重试3次
选项http使用代理头
选项重新修补
选项http服务器关闭
麦克斯康2000
续5000
clitimeout 50000
srvtimeout 50000
前端公众
绑定*:80
acl是\u示例hdr\u端(主机)-i
acl是\u websocket hdr(升级)-i websocket
acl是\u websocket路径\u beg-i/websockets
如果websocket是示例,请使用\u后端ws
默认后端www
后端ws
平衡循环赛
选项forwardfor#此选项设置X-Forwarded-For
超时队列5000
超时服务器86400000
超时连接86400000
服务器apiserver本地主机:权重1 maxconn 1024检查
我让Lighttpd监听8080端口(否则HAProxy无法启动)
提醒您,无需使用mod_proxy,因为它与WebSocket不兼容。改用HAProxy。我在家里的一个简单的个人项目中使用NodeJ和socket io。我没有用lighttpd。
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);
});
# 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