在网上看到一个好东西,于是决定来使用以下。
这个东西之所以好是因为,在自己的项目中尝试了关于sse的东西,可是sse本身就很难控制,加上uwsgi+nginx超时以后会继续占用服务器的线程,而我也搞不清楚服务器要怎么样才可以优雅的关闭连接,折腾了好久,打算直接用这个好用的工具了。
安装
# 克隆 http-stream-push 项目到本地
git clone https://github.com/wandenberg/nginx-push-stream-module.git
# 下载nginx源码自行编译,在编译的时候可以加上这个插件, nginx1.2.0以上的版本
wget http://nginx.org/download/nginx-1.16.1.tar.gz
# unzip
tar zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1
# 配置,并添加nginx-push-stream-module
./configure --add-module=../nginx-push-stream-module --with-http_ssl_module
make
# 安装
sudo make install
# 检查
sudo /usr/local/nginx/sbin/nginx -v
# 测试配置文件
sudo /usr/local/nginx/sbin/nginx -c ../nginx-push-stream-module/misc/nginx.conf -t
# 运行
sudo /usr/local/nginx/sbin/nginx -c ../nginx-push-stream-module/misc/nginx.conf
配置:
找到安装路径(默认 /usr/local/nginx/), 然后编辑目录下的nginx.conf