背景
近期直播类产品更新,出于安全考虑,播放地址由http转换为https。测试环境部署过程中出现一些小波折,特此记录。
nginx安装部署
下载相应安装包,执行以下脚本:
#!/bin/bash
yum -y install gd-devel
yum -y install perl-ExtUtils-Embed
yum -y install perl-CPAN
yum -y install gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel
tar xf nginx_mod_h264_streaming-2.2.7.tar.gz -C /usr/local/
sed -i '158,161s@^@//@g' /usr/local/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c
useradd www -s /sbin/nologin
tar xvf nginx-1.7.8.tar.gz
cd nginx-1.7.8
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_dav_module --with-http_addition_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --with-http_perl_module --with-debug --with-http_image_filter_module --add-module=/usr/local/nginx_mod_h264_streaming-2.2.7
make
make install
#cp -rf nginx.conf /usr/local/nginx/conf
#mkdir vhosts
#cp zy.conf /usr/local/nginx/conf/vhosts
直播间添加特定字段做区分
简单采用rewrite进行配置,详细如下:
server{
listen 80;
server_name 192.168.0.179;
root /;
location ~ \.m3u8 #所有jsp的页面均交由tomcat处理
{
rewrite ^/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).m3u8$ http://192.168.0.104/$1/$6.m3u8 break;
}
location ~ \.ts #所有jsp的页面均交由tomcat处理
{
rewrite ^/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).ts$ http://192.168.0.104/$1/$6.ts break;
}
}
播放地址由http转换为https
需注意nginx编译时有无相应的openssl库文件,ldd nginx查看。
简单采用rewrite进行配置,详细如下:
server{
listen 443 ssl;
server_name 192.168.0.179;
ssl on;
ssl_certificate ssl/server.crt;
ssl_certificate_key ssl/server.key;
keepalive_timeout 60;
access_log logs/ssl-access.log;
error_log logs/ssl-error.log;
root /;
location ~ \.m3u8 #所有jsp的页面均交由tomcat处理
{
rewrite ^/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).m3u8$ http://192.168.0.104/$1/$6.m3u8 break;
}
location ~ \.ts #所有jsp的页面均交由tomcat处理
{
rewrite ^/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).ts$ http://192.168.0.104/$1/$6.ts break;
}
}
附:证书生成
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key server.key_bak
openssl rsa -in server.key_bak -out server.key
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt