nginx—rtmp流媒体服务器搭建

 
分享到:

以Linux服务器为例,讲解搭建nginx流程。


1)下载nginx源码和nginx-rtmp-module源码

nginx官网下载地址:

http://nginx.org/en/download.html


nginx-rtmp-module的github下载地址

https://github.com/arut/nginx-rtmp-module


2)安装支持rtmp和hls的nginx

例如在Linux中把nginx放在目录/nginx_files并解压,解压后的目录是/nginx_files/nginx-1.14.0。把nginx-rtmp-module的源码放在目录/nginx_files/nginx-rtmp-module-master中。进入目录/nginx_files/nginx-1.14.0执行以下命令:

./configure   --add-module=/nginx_files/nginx-rtmp-module-master --with-http_ssl_module

make

make install


3)配置nginx

安装之后的nginx在目录/usr/local/nginx中,修改配置文件/usr/local/nginx/conf/nginx.conf,内容如下:

#user   nobody;

worker_processes   1;

events {

    worker_connections   1024;

}

rtmp {

   server {

    listen 1935;

    chunk_size 4000;

    application live {

      live on;

      hls on;   

      hls_path /tmp/nginx_hls/live;   

      hls_fragment 2s;   

      allow publish 0.0.0.0;

    }

   }

}

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       80;

        server_name   localhost;

        #charset koi8-r;

        #access_log   logs/host.access.log   main;

        location / {

            root   /tmp/nginx_hls;

            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;

        }

    }

}

上述文件内容中指定了rtmp端口是1935,hls端口是80,可自行定义。


3)运行nginx

执行以下命令:

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf




 联系方式
公司电话:0755-36539268
24小时服务:17302669250