前先後後搭建了兩三個星期,終於能夠告一段落,nginx實在是有點強大。寫一篇筆記來記錄一下這個過程當中的思路和解決方案。html
#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 /usr/local/nginx/html/flv_file;
}
# 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;
hls_path /usr/local/nginx/html/flv_file;
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 /home/nairely/Documents/nginxserver/nginx-rtmp-module-master;
}
location /control {
rtmp_control all;
}
location / {
root /home/nairely/Documents/nginxserver/nginx-rtmp-module-master/test/rtmp-publisher;
}
}
server {
listen 80;
server_name localhost;
location / {
root /usr/local/nginx/html/flv_file;
index index.html;
}
location ~ \.flv$ {
root /usr/local/nginx/html/flv_file;
flv;
limit_conn addr 20;
limit_rate 200k;
}
location ~ \.mp4$ {
root /usr/local/nginx/html/flv_file;
mp4;
limit_conn addr 20;
limit_rate 200k;
}
location /hls {
# Serve HLS fragments
alias /usr/local/nginx/html/flv_file;
}
access_log logs/nginxflv_access.log access;
}
}nginx