前前后后搭建了两三个星期,终于可以告一段落,nginx实在是有点强大。写一篇笔记来记录一下这个过程中的思路和解决方案。
worker_processes 30; ##后台进程
error_log /usr/local/nginx/logs/error.log;
##nginx错误日志存放路径
pid /usr/local/nginx/logs/nginx.pid;
events {
use epoll;
##轮训方式
worker_connections 65535;
##允许的最大连接数
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /usr/local/nginx/logs/access.log;
sendfile on;
tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_min_length 1000;
gzip_buffers 4 8k;
gzip_types text/plain;
server {
listen 80;
server_name 192.168.16.69;
#root html;
root /usr/local/nginx/html/flv_file;
#charset koi8-r;
limit_rate_after 5m;
limit_rate 512k;
index index.html;
charset utf-8;
# access_log /usr/local/nginx/logs/host.access.log main;
# location / {
# root /usr/local/nginx/html/flv_file;
# index index.html;
# limit_rate_after 5m;
# limit_rate 512k;
#error_page 404 /404.html;
location ~ \.flv$ {
# root /var/www/flv;
flv;
}
location ~ \.mp4$ {
# root /var/www/mp4;
mp4;
}
}
}
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;
}
}
}
2.配置文件(可支持http,rtmp,hls)
#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;
}
}
来源:https://www.cnblogs.com/lidabo/p/6405261.html