備注:
使用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. 檢驗?zāi)K安裝
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. 總結(jié)
目前只是簡答是試用,功能上還是比較強大的,對于安全的問題择浊,參考文檔有說明。
同時經(jīng)過測試openresty編譯也是支持的荔茬,很好很強大霞揉,在實時web開發(fā)上我們又有了
比較方便的工具,同時減少了大家的工作量癣猾。
對于實際中的一些問題权埠,大家結(jié)合openresty強大的控制能力,可以很容易解決
6. 參考文檔
https://nchan.io/#install
https://nginx.org/en/download.html
https://github.com/slact/nchan