一 .安装环境
1. yum install git
2. git clone git://github.com/wandenberg/nginx-push-stream-module.git
#git clone http://github.com/wandenberg/nginx-push-stream-module.git
NGINX_PUSH_STREAM_MODULE_PATH=$PWD/nginx-push-stream-module
3. yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
wget http://nginx.org/download/nginx-1.5.13.tar.gz
tar xzvf nginx-1.5.13.tar.gz
cd nginx-1.5.13
./configure --add-module=../nginx-push-stream-module
make
make install
4. 测试nginx
/usr/local/nginx/sbin/nginx -t
二. 基本配置
http块配置:
push_stream_shared_memory_size 256k;
server块配置:
location /channels-stats {
push_stream_channels_statistics;
push_stream_channels_path $arg_id;
}
location /pub {
push_stream_publisher admin;
push_stream_channels_path $arg_id;
}
location ~ /sub/(.*) {
push_stream_subscriber;
push_stream_channels_path $1;
}
三. 应用demo
1. 订阅
curl -s -v 'http://localhost/sub/my_channel_1'
curl -s -v 'http://localhost/sub/your_channel_1'
curl -s -v 'http://localhost/sub/your_channel_2
2. 发布
curl -s -v -X POST 'http://localhost/pub?id=my_channel_1' -d 'Hello World!'
curl -s -v -X POST 'http://localhost/pub?id=your_channel_1' -d 'Hi everybody!'
curl -s -v -X POST 'http://localhost/pub?id=your_channel_2' -d 'Goodbye!'
3. 查询
curl -s -v 'http://localhost/channels-stats'
4. 删除
curl -s -v -X DELETE 'http://localhost/pub?id=my_channel_1'