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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • webstorm的永久激活码2021[最新免费获取]

    (webstorm的永久激活码2021)本文适用于JetBrains家族所有ide,包括IntelliJidea,phpstorm,webstorm,pycharm,datagrip等。IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月28日
    742
  • sublime text3配置ctrl+鼠标左键进行函数跳转「建议收藏」

    sublime text3配置ctrl+鼠标左键进行函数跳转「建议收藏」点击Preferences->BrowsePackages进入Packages目录,然后打开User目录,查看User目录里面有没有Default(Windows).sublime-mousemap文件,如果没有则创建一个。这个文件是用来配置sublime的鼠标操作的。在文件中输入如下内容:[ { “button”:”button2″, “count”:1, “m…

    2022年7月11日
    111
  • 计算机考研各省份学校,想考研究生,哪个省份的高校更容易考上?

    计算机考研各省份学校,想考研究生,哪个省份的高校更容易考上?广东省2020年报考人数为17.4万,比去年增长24.3%。考研人数在过去的5年里飞速增长,自2015年的5.16万到2020年的17.4万,五年时间里翻了两倍多,涨幅在国内名列前茅。山东省2020年硕士研究生招生考试准考人数共313190人,比去年增加58704人,增幅为23.1%,同样每年新增几万的考研人。江苏省2020年共有24.9万名考生报名参加硕士研究生考试,比去年增长17.7%,再创历…

    2022年5月22日
    74
  • Java基础学习教程,eclipse简单使用教程(Java集成开发工具)

    Java基础学习教程,eclipse简单使用教程(Java集成开发工具)使用集成开发工具eclipse1、java的集成开发工具很多,包括:eclipse、IntellijIDEA、netbeans….. eclipse: IBM开发的。eclipse翻译为:日食。寓意吞并SUN公司(SUN是太阳。)最终没有成功,SUN公司在2009年的时候被oracle甲骨文公司收购。eclipse在以前的开发中使用非常多,但是由于IDEA工具的出现,让eclipse的用户大大减少,目前eclipse占市场份额30%。IDEA占市场份额60%,剩下10%是其他的开

    2022年6月28日
    30
  • python求解中位数、均值、众数

    python求解中位数、均值、众数首先定义一个数据,在这里我假定为:num=[2,3,2,5,1,0,1,2,9]一、求中位数    中位数(又称中值,英语:Median),统计学中的专有名词,代表一个样本、种群或概率分布中的一个数值,其可将数值集合划分为相等的上下两部分。对于有限的数集,可以通过把所有观察值高低排序后找出正中间的一个作为中位数。如果观察值有偶数个,则中位数不唯一,通常取最中间的两个数值的平均数…

    2025年12月14日
    4

发表回复

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

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