小编lor*_*bac的帖子

使用lighttpd重定向端口80上的websocket流量

我有一个托管在lighttpd上的网站,可在"www"子域访问.我还有一个聊天服务器在端口8124上侦听node.js和socket.io.

我希望所有客户端流量都发生在端口80上,方法是将所有请求重定向到"chat"子域到端口8124.所以我启用了mod_proxy并在lighttpd.conf中添加了:

$HTTP["host"] == "chat.myserver.com" {
    proxy.server = (
            "" => ((
                    "host" => "78.128.79.192",
                    "port" => "8124"
            ))
    )
}
Run Code Online (Sandbox Code Playgroud)

在客户端,当我连接到websocket时,

var socket = io.connect('http://chat.myserver.com');
Run Code Online (Sandbox Code Playgroud)

我从node.js得到了正确的消息:

debug - client authorized
info  - handshake authorized 6067470561567883577
debug - setting request GET /socket.io/1/websocket/6067470561567883577
debug - set heartbeat interval for client 6067470561567883577
debug - client authorized for 
debug - websocket writing 1::
Run Code Online (Sandbox Code Playgroud)

但浏览器出错:

Firefox can't connect to server ws://chat.myserver.com/socket.io/1/websocket/6067470561567883577
Run Code Online (Sandbox Code Playgroud)

当然,如果我直接连接到端口8124,一切正常:

var socket = io.connect('http://www.myserver.com:8124');
Run Code Online (Sandbox Code Playgroud)

但是,正如我所说,我希望所有客户端流量都在端口80上.它是否可能?

lighttpd websocket node.js socket.io

7
推荐指数
1
解决办法
8057
查看次数

MongoDB - 独特的多键索引无法按预期工作

我在MongoDB中遇到了多键索引的问题.

我有一个名为的集合users,其文档看起来或多或少像这样:

{
  "_id": ObjectId(),
  "name": "John Smith",
  ...
  "votes": [
    {
      "type": "news",
      "votedObjectId": "123"
    },
    {
      "type": "blog",
      "votedObjectId": "124"
    },
    {
      "type": "news"
      "votedObjectId": "225"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我想创建一个索引votedObjectId,我希望用户只为每篇文章投票一次.

我确保了一个唯一的索引(代码在node.js - mongoskin模块中):

`this.ensureIndex({'votes.votedObjectId': 1}, {unique: true}, ...)`
Run Code Online (Sandbox Code Playgroud)

然后我尝试了两次同一篇文章的投票,它实际上添加了两次完全相同的投票.

如何确保数组不包含重复元素?

PS

我使用{safe:true}执行所有插入操作,并且我获得的重复值不会被插入操作返回,而是实际插入到集合中.

unique-index mongodb

3
推荐指数
1
解决办法
3414
查看次数

标签 统计

lighttpd ×1

mongodb ×1

node.js ×1

socket.io ×1

unique-index ×1

websocket ×1