Linux安装Nginx并集成nginx-http-flv-module

1、Linux安装Nginx前置环境

yum install gcc-c++
yum install -y openssl openssl-devel
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel

2、安装Nginx和nginx-http-flv-module

下载

Nginx: https://nginx.org/download
nginx-http-flv-module: https://github.com/winshining/nginx-http-flv-module

nginx可自行选择版本下载 ,nginx-http-flv-module可以通过git下载

解压安装

tar -zxvf nginx-1.18.0.tar.gz
unzip -o nginx-http-flv-module-master.zip
mv nginx-http-flv-module-master nginx-http-flv-module

cd nginx-1.18.0

./configure --add-module=/usr/local/nginx-http-flv-module --with-http_ssl_module
make
make install

3、配置Nginx并启动

查找nginx安装目录

whereis nginx
cd /usr/local/nginx/conf

vi 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;
user root;
 
events {
    worker_connections  1024;
}
 
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp_socket_dir /tmp;
rtmp{
        out_queue 4096;
        out_cork 8;
        max_streams 128;
        timeout 15s;
        drop_idle_publisher 15s;
        log_interval 5s;
        log_size 1m;
        server{
         listen 1736;
         application live{
                 live on;
                 gop_cache on;
		record off;
          }
         application hls{
          live on;
          hls on;
          hls_path /usr/local/nginx/html/hls;
        }
         application dash{
           live on;
           dash on;
           dash_path /usr/local/nginx/html/dash;
        }
	}
}
 
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  logs/access.log  main;
 
    sendfile        on;
    #tcp_nopush     on;
 
    #keepalive_timeout  0;
    keepalive_timeout  65;
 
    #gzip  on;
 
    server {
        listen       1735;
 
	location /live{
                flv_live on;
                chunked_transfer_encoding  on;
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Credentials' 'true';
        }
        location /hls{
                types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
                 }
                 root html;
                 add_header 'Cache-Control' 'no-cache';
        }
         location /dash {
            root /usr/local/nginx/html/dash;
            add_header 'Cache-Control' 'no-cache';
        }
 
        location /stat {
              rtmp_stat all;
              rtmp_stat_stylesheet stat.xsl;
         }
        location /stat.xsl {
          root /usr/local/nginx/nginx-http-flv-module;
        }
 
         location /control {
            rtmp_control all; #configuration of control module of rtmp
        }
    
    }
    server {
        listen       8088;
        server_name  localhost;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
        location / {
            root   html;
            index  index.html index.htm;
        }
 
        #error_page  404              /404.html;
 
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

启动

cd ../sbin

./nginx

你可能感兴趣的:(linux,linux,nginx,http)