全国服务热线400-0551-422 在线咨询 留言/需求提交

nginx点播和直播配置

【摘要】 nginx点播和直播配置
#filename:nginx.conf
#user nobody;
worker_processes  1;

error_log logs/error.log;
#error_log logs/error.log  notice;
#error_log logs/error.log  info;

pid logs/nginx.pid;

events {
use epoll;
worker_connections  1024;
}

rtmp {
server {
listen 1935;
chunk_size 4000;

# video on demand
application vod {
play /video;
}

# HLS
# HLS requires libavformat & should be configured as a separate
# NGINX module in addition to nginx-rtmp-module:
# ./configure … –add-module=/path/to/nginx-rtmp-module/hls …
# For HLS to work please create a directory in tmpfs (/tmp/app here)
# for the fragments. The directory contents is served via HTTP (see
# http{} section in config)
#
# Incoming stream must be in H264/AAC/MP3. For iPhones use baseline H264
# profile (see ffmpeg example).
# This example creates RTMP stream from movie ready for HLS:
#
# ffmpeg -loglevel verbose -re -i movie.avi  -vcodec libx264
#    -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1
#    -f flv rtmp://localhost:1935/hls/movie
#
# If you need to transcode live stream use ‘exec’ feature.
#
application hls {
hls on;
live on;
hls_path /video/live;
hls_fragment 10s;
}
}
}

http{

include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;

#log format

log_format  access  ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” $http_x_forwarded_for’;

#定义一个名为addr的limit_zone,大小10M内存来存储session
limit_conn_zone $binary_remote_addr zone=addr:10m;

server {
listen 8080;
server_name localhost;

# HTTP can be used for accessing RTMP stats
# This URL provides RTMP statistics in XML
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}

location /stat.xsl {
root /video/config/nginx-rtmp-module-master;
}

location /control {
rtmp_control all;
}

location / {
root /video/config/nginx-rtmp-module-master/rtmp-publisher;
}
}

server {
listen 80;
server_name player.hfyefan.cn;

location / {
root /video/wwwroot;
index index.html;
}

location ~ \.flv$ {
root /video;
flv;
limit_conn addr 20;
limit_rate 200k;
}

location ~ \.mp4$ {
root /video;
mp4;
limit_conn addr 20;
limit_rate 200k;
}

location /hls {
#Serve HLS fragments
alias /video/live;
}

access_log  logs/nginxflv_access.log access;
}

}

资讯推荐阅读