Nginx搭建视频点播和视频直播服务器[通俗易懂]

Nginx搭建视频点播和视频直播服务器[通俗易懂]Nginx搭建视频点播和视频直播服务器一·、环境:Centos7,(推荐,Ubuntu不是很好用,经常会有一些莫名其妙的报错)Nginx1.10.1二、系统环境搭建首先,我是不建议自己一个个去安装这些软件的,耗时耗力,而且,容易出错,所以,最好使用yuminstall***命令安装,出错的概率小。资源链接:链接:https://pan.baidu.com/s/1WmJYpQ_b…

大家好,又见面了,我是你们的朋友全栈君。

Nginx搭建视频点播和视频直播服务器

一·、环境:
Centos 7,(推荐,Ubuntu不是很好用,经常会有一些莫名其妙的报错)
Nginx1.10.1
二、系统环境搭建
首先,我是不建议自己一个个去安装这些软件的,耗时耗力,而且,容易出错,所以,最好使用yum install ***命令安装,出错的概率小。
在这里插入图片描述
资源链接:链接:https://pan.baidu.com/s/1WmJYpQ_b089Oj783FZjX0g
提取码:bk0v
1、首先说下默认安装流程
(1)、yum install gcc gcc-c++
(2)、yum install openssl openssl-devel
(3)、yum insall pcre pcre-devel
(4)、yum install zlib zlib-devel
(5)、重点,下载nginx-rtmp-module-master
命令:git clone https://github.com/arut/nginx-rtmp-module.git
解压:
(6)、编译安装nginx
进入到解压之后的目录下,./configure –prefix=/usr/local/nginx –add-module=/home/admin/ftp/software/nginx-rtmp-module-master
注意:有时候编译的时候可能会报错,比如openssl找不到,而你输入openssll是有显示的,这是为什么,是因为你没有安装openssl-devel。
编译,注意:/home/admin/ftp/software/是你自己定义的rtmp包解压之后的目录。
2、非默认的,下载压缩包,解压后,编译(./configure –prefix=/usr/local/yourname)->make–>make install。出错率比较高,不交易这样做。
三、启动nginx
测试的时候,发现不论是service nginx start还是systemctl start nginx都不起作用,这就需要我们自己将nginx这个添加进服务里面去。在/etc/init.d/下创建一个nginx文件。(创建方法,vi nginx——>:wq退出保存)。

特别注意:#!/bin/sh一定要放在第一行,复制粘贴的时候不要忘记。

#!/bin/sh
# nginx - this script starts and stops the nginx daemin
#
# chkconfig:   - 85 15
 
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#               proxy and IMAP/POP3 proxy server
 
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid
 
# Source function library.
 
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
 
. /etc/sysconfig/network
 
# Check that networking is up.
 
[ "$NETWORKING" = "no" ] && exit 0
 
nginx="/usr/local/nginx/sbin/nginx"
 
prog=$(basename $nginx)
 
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
 
lockfile=/var/lock/subsys/nginx
 
start() {
 
    [ -x $nginx ] || exit 5
 
    [ -f $NGINX_CONF_FILE ] || exit 6
 
    echo -n $"Starting $prog: "
 
    daemon $nginx -c $NGINX_CONF_FILE
 
    retval=$?
 
    echo
 
    [ $retval -eq 0 ] && touch $lockfile
 
    return $retval
 
}
 
 
stop() {
 
    echo -n $"Stopping $prog: "
 
    killproc $prog -QUIT
 
    retval=$?
 
    echo
 
    [ $retval -eq 0 ] && rm -f $lockfile
 
    return $retval
 
}
 
 
 
restart() {
 
    configtest || return $?
 
    stop
 
    start
 
}
 
 
reload() {
 
    configtest || return $?
 
    echo -n $"Reloading $prog: "
 
    killproc $nginx -HUP
 
    RETVAL=$?
 
    echo
 
}
 
force_reload() {
 
    restart
 
}
 
 
configtest() {
 
  $nginx -t -c $NGINX_CONF_FILE
 
}
 
 
 
rh_status() {
 
    status $prog
 
}
 
 
rh_status_q() {
 
    rh_status >/dev/null 2>&1
 
}
 
case "$1" in
 
    start)
 
        rh_status_q && exit 0
        $1
        ;;
 
    stop)
 
 
        rh_status_q || exit 0
        $1
        ;;
 
    restart|configtest)
        $1
        ;;
 
    reload)
        rh_status_q || exit 7
        $1
        ;;
 
 
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
 
 
    condrestart|try-restart)
 
        rh_status_q || exit 0
            ;;
 
    *)
 
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac

nginx=”/usr/local/nginx/sbin/nginx”这里的文件目录为你自己的目录,得确认你sbin目录下有nginx这个文件。
NGINX_CONF_FILE=”/usr/local/nginx/conf/nginx.conf”这个也同上,注意自己的目录。
lockfile=/var/lock/subsys/nginx这一行不是很重要,我也不是很理解,我的subsys下并没有nginx这个文件,但是整个运行时没有报错的。
四、systemctl start nginx
五、修改nginx.conf文件。

rtmp {
        server {
            listen 1935;
            #server_name localhost;
            application liveApp {
                live on;
             }

             application vod {
                play /home/admin/ftp/video;//你的视频存放的位置
             }

             application vod_http {
                 play http://119.23.234.4/vod;
             }

             application hls {
                 live on;
                 hls on;
                 hls_path /home/admin/ftp/software/nginx/objs/addon/hls;#注意为你的实际目录,可以通过find / -name hls查找。
             }
        }
}
 location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
           root /usr/local/nginx/nginx-rtmp-module/;#注意,确保你的nginx下有这个文件,没有的话,可以把你解压后的文件复制粘贴过来。这里填你的原来的目录报错。
        }

        location /hsl {
          types {
            application /vnd.apple.mpegurl m3u8;
            video/mp2t ts;
          }
          alias  /usr/local/nginx/nginx-rtmp-module/hls;//复制粘贴过来之后的hls目录。
          add_header Cache-Control no-cache;
        }

        #location /dash {
            #root /tmp;
            #add_header Cache-Control no-cache;
        #}

合理安装之后,/usr/local/nginx下应当是有rtmp模块文件的,没有也没关系,只要你编译nginx的时候,他没有报错,(没有报not found错误)。把nginx-rtmp-module复制粘贴过去即可。
六、演示:
在这里插入图片描述
在这里插入图片描述

去年写的博客,今天做一个补充:

https://blog.csdn.net/zhangbijun1230/article/details/82356611
https://blog.csdn.net/weixin_34261739/article/details/88917741
https://www.linuxidc.com/Linux/2018-10/154934.htm

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/130654.html原文链接:https://javaforall.net

(0)
上一篇 2022年6月14日 上午8:16
下一篇 2022年6月14日 上午8:36


相关推荐

  • GFS配置

    GFS配置gfs 挂载点 dataxenserve 0 3 22310 0 3 224 在 3 42 和 3 43 服务器上各添加一块盘 mkfs xfs dev xvdimkdir data data sspecho dev xvdi data data ssp

    2026年3月19日
    3
  • Spring学习总结(一)入门

    一、Spring的概述1、什么是SpringSpring:SE/EE开发的一站式框架。一站式框架:有EE开发的每一层解决方案。WEB层 :SpringMVCService层 :Spring的Bean管理,Spring声明式事务DAO层 :Spring的Jdbc模板,Spring的ORM模块2、为什么学习Spring3、常用Spring的版本 &…

    2021年11月30日
    61
  • python爬虫–协程(初识)

    python爬虫–协程(初识)

    2021年4月16日
    170
  • python os.environ.set_os.environ详解

    python os.environ.set_os.environ详解我们想要用 Python 获得一些有关系统的各种信息的时候就不得不想到 os 的 environ 那这里面都具体包含了那些内容呢 简介对于官方的解释 environ 是一个字符串所对应环境的映像对象 这是什么意思呢 举个例子来说 environ HOME 就代表了当前这个用户的主目录 例子比如刚刚举例的 os environ HOME 在 linux 中适用而在 windows 下面是没有这个 key 的 在 windo

    2026年3月18日
    2
  • 求教:session.getAttribute()获取不到session.setAttribute()的值

    求教:session.getAttribute()获取不到session.setAttribute()的值很简单的一个web项目中,用户登陆成功后,在后台用session.setAttribute(“user”),记录登陆的用户信息,在跳到主页面(index.jsp)的时候,先经过后台处理,通过登陆的用户信息,查询相应的权限资源,这时用session.getAttribute(“user”),取到用户的信息,现在就是取不到用户信息,取到的值为null,经过不断测试,原因应该在后台登陆方法中的sessi…

    2022年10月16日
    3
  • path是什么意思啊_on the path

    path是什么意思啊_on the path投影投影是JMESPath的关键特性之一。它允许您将表达式应用于元素集合。有五种投影:列表投影切片投影对象投影展平投影过滤投影处理投影需要注意的点投影分为两个步骤。左侧(LHS)创建一

    2022年7月30日
    9

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号