javascript - Can't access to socket.io.js on Raspberry Pi with Lighttpd [Node.JS & Socket.IO] -
i'm new node.js , socket.io since yesterday.
i try make node.js , socket.io work on raspberry pi doesn't seem to. i can't access <myip>:1337/socket.io/socket.io.js. have followed this tutorial lighttpd.conf file seems so:
$http["host"] == "<myurltomywebsite>" { proxy.server = (" " => (( "host" => "<myip>", "port" => 1337) ) ) my server.js so:
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); }); and bind disusr , newusr events in client.js display number of connected users in div.
everything looks fine on localhost but, in production environment, cannot link socket.io.js file on 1337 port. honest, i'm not sure address use? (url of website appended :1337, localhost, other address have created?)
any appreciated. thanks!
i resolved problem!
i linked socket.io.js : <script type="text/javascript" src="/socket.io/socket.io.js"></script>
i used haproxy instead of lighttpd mod_proxy specified in this question
here conf file (amend <...> per configuration):
# 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 # sets x-forwarded-for timeout queue 5000 timeout server 86400000 timeout connect 86400000 server apiserver localhost:<port> weight 1 maxconn 1024 check and made lighttpd listened 8080 port (otherwise haproxy wouldn't start).
remind there no need use mod_proxy known not compatible websockets. use haproxy instead.
Comments
Post a Comment