Nchan 安装试用(openresty 同时支持),


备注:

使用nginx最新的源码包(nginx-1.13.6),以及源码安装

1. 下载源码包(nginx+ Nchan)

https://nginx.org/download/nginx-1.13.6.tar.gz

wget https://github.com/slact/nchan/archive/v1.1.10.zip

2. 配置安装(对于需要的依赖按照提示即可)

./configure --add-module=/opt/nginx/nchan-1.1.10

make  && makeinstall

3. 检验模块安装

sbin/nginx -V

nginx version:nginx/1.13.6

builtbygcc4.8.520150623(RedHat4.8.5-16) (GCC)

configurearguments:--add-module=/opt/nginx/nchan-1.1.10

3. 使用

location=/sub {

nchan_subscriber;

nchan_channel_id$arg_id;

}

location=/pub {

nchan_publisher;

nchan_channel_id$arg_id;

}

4. 测试

// http post data

curl\

-H"Content-type: application/json"\

-d'{"name": "dalong","age":333}'\

'http://xxxxx:9090/pub?id=demo'

// browser recived data

var ws = new WebScoket("ws://xxxxx:9090/sub?id=demo")

ws.onmessage=funciton(data){

console.log(data)

}

效果

5. 总结

目前只是简答是试用,功能上还是比较强大的,对于安全的问题,参考文档有说明。

同时经过测试openresty编译也是支持的,很好很强大,在实时web开发上我们又有了

比较方便的工具,同时减少了大家的工作量。

对于实际中的一些问题,大家结合openresty强大的控制能力,可以很容易解决

6. 参考文档

https://nchan.io/#install

https://nginx.org/en/download.html

https://github.com/slact/nchan

相关内容

    暂无相关文章