背景:
阅读新闻
利用Nginx搭建http和rtmp协议的流媒体服务器
[日期:2013-02-07] 来源:Linux社区 作者:5iqiong [字体:]
二、安装Nginx相关模块
#tar zxvf nginx_mod_h264_streaming-2.2.7.tar.gz
#git clone git://github.com/arut/nginx-rtmp-module.git
#tar zxvf pcre-8.12.tar.gz
#cd pcre-8.12
#./configure
#make && make install
#tar zxvf nginx-1.2.6.tar.gz
#cd nginx-1.2.6
#./configure --prefix=/usr/local/nginx --add-module=../nginx_mod_h264_streaming-2.2.7 --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_mp4_module --add-module=../nginx-rtmp-module --add-module=../nginx-rtmp-module/hls --with-cc-opt=-I/opt/ffmpeg/include --with-ld-opt='-L/opt/ffmpeg/lib -Wl,-rpath=/opt/ffmpeg/lib'
#make && make install
三、修改nginx主配置文件,配置虚拟主机(这里我们暂时只配置和测试点播,直播请看借鉴地址):
user nobody nobody;
worker_processes 4;
error_log logs/nginx_error.log info;
pid logs/nginx.pid;
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
#rtmp_auto_push on;
rtmp {
server {
listen 1935;
application vod {
play /opt/media/nginxrtmp/flv;
}
}
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m ;
limit_conn_zone $binary_remote_addr zone=perip:256k;
limit_conn_log_level notice;
sendfile on;
tcp_nopush on;
keepalive_timeout 6000;#测试并发临时调大
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#log format
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
#支持flv
server
{
listen 8081;
server_name 192.168.0.33;
root /opt/pub/media/nginx; #http协议时候,flv视频位置
location ~ .*.(flv|swf|mp4|wma|wmv)$ {
valid_referers none blocked *.xxxx.com ;
if ($invalid_referer) {
return 403;
}
}
location ~ \.flv$ {
flv;
limit_conn one 20;#限制客户端并发连接数
limit_rate 200k;#限制每客户端最大带宽
}
location ~ \.mp4$ {
flv;
limit_conn one 20;
limit_rate 200k;
}
access_log logs/nginxflv_access.log main;
}
server
{
listen 8082;
server_name 192.168.0.33;
index index.html;
location / {
root /opt/pub/media/nginx-rtmp;
}
access_log logs/nginxrtmpflv_access.log main;
}
server {
listen 8080;
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /opt/pub/soft/nginx-rtmp-module;
}
location / {
root /opt/pub/soft/nginx-rtmp-module/test/rtmp-publisher;
}
}
:8080/stats 查看rtmp客户请求信息
:8081/index.html 查看nginx http协议时候的flv视频
:8082/index.html 查看nginx rtmp协议时候的flv视频
相关资讯
本文评论 查看全部评论 (0)
尊重网上道德,遵守中华人民共和国的各项有关法律法规 承担一切因您的行为而直接或间接导致的民事或刑事法律责任 本站管理人员有权保留或删除其管辖留言中的任意内容 本站有权在网站内转载或引用您的评论 参与本评论即表明您已经阅读并接受上述条款
评论声明
最新资讯