Nginx HTTP PUSH 上的会话/授权 comet

发布于 2024-09-11 08:54:48 字数 300 浏览 3 评论 0原文

Nginx 的 HTTP PUSH 方法相对简单。涉及 3 方:订阅者(接收者)、发布者(发送者),服务器本身充当组播服务器。

Nginx还可以分成不同的频道,具有不同的频道ID供用户访问。

但我仍然不知道如何仅对登录用户授权/限制内容,或仅向该用户发送所需的数据,而不是将其多播给任何知道频道 ID 的人。

如果可能的话,是否有办法只使用一个通道并有选择地向用户发送数据?

目前我在同一个数据库上运行,但发送器是用 ruby​​ 编写的,使用 nginx,前端是使用 PHP/GWT 编写的。

非常感谢

The Nginx approach to HTTP PUSH is relatively simple. There are 3 party involve: Subcriber (receiver), Publisher (sender), and the server itself act as multicast server.

Nginx can also separate into different channel with different channel ID that user can access.

But I still don't know how to authorize/limit content only for logged in user, or send only the data needed to that user, instead of multicast it to anyone know about the channel ID.

If possible, are there anyway to use only a channel and send data to user selectively?

Currently i am running on the same database, but the Sender is writen in ruby, using nginx, and the front end is writen using PHP/GWT.

Thank you very much

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傾城如夢未必闌珊 2024-09-18 08:54:49

也许您可以使用我的 http_push_module 模块的分支,它实现了对通道的细粒度安全访问。它提供通道的过期时间和每个客户端 IP/每个通道的安全性(如果需要的话,它还会添加 jsonp 支持,作为一个优点):

https://github.com/Kronuz/nginx_http_push_module

使用该模块,您可以为登录的用户提供一个有效的密钥以供使用(甚至可以过期,或者仅使用 FFFFFFFF 作为过期时间)日期,以便它永不过期),并根据您的需要对他们的访问进行限制,甚至可以使用嵌入在密钥中的 IP 地址来“打开”通道。我希望这有帮助。

Maybe you can use my fork of the http_push_module module, it implements fine grain security access to channels. It provides expiration times to channels and per-client-IP/per-channel security (it additionally adds jsonp support if you need it, as a plus):

https://github.com/Kronuz/nginx_http_push_module

Using the module you can give your logged in users a valid key to use (which can even expire, or just use FFFFFFFF otherwise as the expiration date so it never expires) and be as restrictive as you want with their access, even by using their IP address embedded in the key to "open" the channel. I hope this helps.

北渚 2024-09-18 08:54:48

这是我的设置:
>

 位置 = /broadcast/sub {
                   默认类型文本/json;
                  设置 $push_channel_id $arg_channel;
                  推送订阅者;
                  Push_subscriber_concurrency 广播;
                  Push_channel_group 广播;
              }

              位置= /广播/酒吧{
                  设置 $push_channel_id $arg_channel;
                  推送发布者;
                  Push_min_message_buffer_length 5;
                  Push_max_message_buffer_length 20;
                  Push_message_timeout 10s;
                  Push_channel_group 广播;
              }

我用curl发送新消息

    $ch=curl_init($pub_url);
    $data = array('status' => $message);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("内容类型:
文本/json"));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $return =curl_exec($ch);
    卷曲_关闭($ch);

感谢您的任何提示...

This is my setup:
>

              location = /broadcast/sub {
                   default_type  text/json;
                  set $push_channel_id $arg_channel;
                  push_subscriber;
                  push_subscriber_concurrency broadcast;
                  push_channel_group broadcast;
              }

              location = /broadcast/pub {
                  set $push_channel_id $arg_channel;
                  push_publisher;
                  push_min_message_buffer_length 5;
                  push_max_message_buffer_length 20;
                  push_message_timeout 10s;
                  push_channel_group broadcast;
              }

I send new messages with curl

    $ch = curl_init($pub_url);
    $data = array('status' => $message);
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:
text/json"));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $return = curl_exec($ch);
    curl_close($ch);

Thanks for any hints...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文