做了一个基于openresty 的在线聊天系统 分享一下

175 views
Skip to first unread message

瞿秋丰

unread,
Jun 24, 2014, 10:51:51 PM6/24/14
to open...@googlegroups.com
服务端采用 icomet


openresty使用最新版

cd icomet
make
./comet-server icomet.conf &
文件夹内有demo范例 稍加修改就可以跑起来

server
 {
                listen       80;
                server_name  icomet.test.com;
                index  chat.html;
                root /home/lamp/icomet/demo/web;
                #lua_code_cache off;
                location ~ ^/icomet/.*
                {
                        rewrite ^/icomet/(.*) /$1 break;
                        proxy_read_timeout 60;
                        proxy_connect_timeout 60;
                        proxy_buffering off;
                        proxy_pass   http://127.0.0.1:8000;
                }
                location ~ ^/front/.*
                {
                        rewrite ^/front/(.*) /$1 break;
                        proxy_read_timeout 60;
                        proxy_connect_timeout 60;
                        proxy_buffering off;
                        proxy_pass   http://127.0.0.1:8100;
                }
                location /sign
                {
                     default_type text/plain;
                     content_by_lua_file lua/sign.lua;
                }
                location /push
                {
                     default_type text/plain;
                     content_by_lua_file lua/push.lua;
                }
                access_log  /dev/null;
                error_log   /dev/null;
}

sign.lua

local cname   = ngx.var.arg_cname
local cb         = ngx.var.arg_cb
local url         = "/icomet/sign"
local res,error = ngx.location.capture(url,
   { args = { cname  = cname ,cb = cb}}
)
if res.status == 200 then
  ngx.say(res.body)
  else
  ngx.exit(0)
end


push.lua
local cname   = ngx.var.arg_cname
local content  = ngx.unescape_uri(ngx.var.arg_content)
local url     = "/icomet/push"
local res,error = ngx.location.capture(url,
   { args = { cname  = cname ,content = content}}
)
if res.status == 200 then
  ngx.say(res.body)
  else
  ngx.exit(0)
end

修改   
icomet /demo/web/js/chat.js

var sign_url = 'http://' + app_host + path + '/php/sign.php';
var pub_url = 'http://' + app_host + path + '/php/push.php?cb=?';
替换成
var sign_url = 'http://' + app_host + path + '/sign?test=1';
var pub_url = 'http://' + app_host + path + '/push?cb=?';

icomet_host = ps[0] + ':8100';
替换成
icomet_host = ps[0];


绑定本机hosts
服务端ip     icomet.test.com

浏览器访问 http://icomet.test.com

Harold.Miao

unread,
Jun 25, 2014, 3:34:13 AM6/25/14
to open...@googlegroups.com
建议在github建个代码库   这样很乱

瞿秋丰 <quqi...@gmail.com>于2014年6月25日星期三写道:
--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html


--

Best Regards,
Harold Miao

Jakin

unread,
Jun 25, 2014, 4:37:40 AM6/25/14
to openresty
其实程序的内在还是使用icomet ,只是用lua 嵌套了一层而已~~~ 其实就算不是用这个也是一样可以的。


------------------ 原始邮件 ------------------
发件人: "Harold.Miao"<miaoh...@gmail.com>;
发送时间: 2014年6月25日(星期三) 下午3:34
收件人: "openresty"<open...@googlegroups.com>;
主题: Re: [openresty] 做了一个基于openresty 的在线聊天系统 分享一下
订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
发言: 请发邮件到 openresty@googlegroups.com
退订: 请发邮件至 openresty+unsubscribe@googlegroups.com

瞿秋丰

unread,
Jun 25, 2014, 4:55:14 AM6/25/14
to open...@googlegroups.com, 8980...@qq.com
嗯  同意
有需要做在线聊天的朋友 用这个方案是最快的  websocket 也可以
lua做 web层 性能最好  作者没有提供lua版本的(只有php版本)
openresty方案 可以高速把聊天记录写入mysql
不是用这个也是一样可以的   其实可以选择不一样   所以我觉得有必要分享下


在 2014年6月25日星期三UTC+8下午4时37分40秒,Jakin写道:
订阅: 请发空白邮件到 openresty+subscribe@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages