title: 阿里云服务器搭建Nginx+rtmp推流服务器

categories:[Centos]

tags:[音视频编程]

date: 2021/11/16

一、前期准备

服务器操作系统:CentOS Linux release 8.4.2105

Nginx版本:nginx-1.18.0.tar.gz

RTMP模块:nginx-rtmp-module

推流工具:OBS-Studio/VLC

拉流工具:VLC

二、搭建编译环境

1.安装依赖

新建的服务器先安装一些依赖,或者编译的时候看错误需要什么就安装什么

sudo yum install gcc make pcre pcre-devel openssl openssl-devel

2.下载nginx-1.18.0.tar.gz和nginx-rtmp-module

wget https://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz #解压
git clone https://github.com/arut/nginx-rtmp-module

3.配置和编译安装

#nginx源码文件夹和rtmp模块源码文件夹在同一目录下
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx  --add-module=../nginx-rtmp-module  --with-http_ssl_module
sudo make
sudo make install

4.查看安装结果

 /usr/local/nginx/sbin/nginx -v#输出nginx version: nginx/1.18.0即为安装成功

三、配置Nginx

1.设置Nginx开机启动

创建Nginx服务文件

vim /usr/lib/systemd/system/nginx.service

创建Nginx服务文件,输入以下内容

[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop[Install]
WantedBy=multi-user.target

启动Nginx服务

sudo systemctl start nginx
sudo systemctl enable nginx

2.修改Nginx的配置文件

vim /usr/local/nginx/conf/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;events {worker_connections  1024;
}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   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;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}#server#{#       listen 8080;#       location /stat{#           rtmp_stat all; #所有状态#           rtmp_stat_stylesheet stat.xsl #state的样式表#           }#       location /stat.xsl{#           root /root/workspace/tmp/rtmp/nginx-rtmp-module;#state的样式表路径#   }# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}

修改后

rtmp_auto_push on;rtmp {server {listen 1935;application live {live on;hls on;hls_fragment 3s;hls_playlist_length 10s;hls_path /usr/local/nginx/html/hls;}application hls {live on;hls on;hls_cleanup off;hls_fragment 3s;hls_playlist_length 10s;hls_path /usr/local/nginx/html/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 {worker_connections  1024;
}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   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;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {#    proxy_pass   http://127.0.0.1;#}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {#    root           html;#    fastcgi_pass   127.0.0.1:9000;#    fastcgi_index  index.php;#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;#    include        fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one##location ~ /\.ht {#    deny  all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}#server#{#       listen 8080;#       location /stat{#           rtmp_stat all; #所有状态#           rtmp_stat_stylesheet stat.xsl #state的样式表#           }#       location /stat.xsl{#           root /root/workspace/tmp/rtmp/nginx-rtmp-module;#state的样式表路径#   }# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}
}

3.重启Nginx,开启Centos端口

开启1935/80/8080端口

sudo firewall-cmd --add-port=1935/tcp --permanent
sudo firewall-cmd --add-port=80/tcp --permanent
sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reload

阿里云后台开启对应的端口

重启ngxin服务

 sudo systemctl restart nginx

浏览器输入服务器IP出现Welcome to nginx!,nginx配置结束

四、测试

1.下载OBS-Studio

官网地址:https://obsproject.com/zh-cn/download,下载完一路安装就行

2.下载VLC

官网地址:https://www.videolan.org/,下载完一路安装就行

3.设置OBS-Studio的推流地址

打开OBS,在 文件 -> 设置 -> 推流 填入 rtmp://服务器IP:1935/live/

设置好了OBS-Studio添加一个屏幕捕获,点击开始推流

4.VLC拉流

打开VLC,媒体 -> 打开网络串流 -> 网络

输入:rtmp://服务器IP:1935/live/demo

​ http://服务器IP/hls/demo.m3u8

阿里云服务器搭建Nginx+rtmp推流服务器相关推荐

  1. 宝塔 搭建 nginx rtmp 流媒体服务器

    宝塔 搭建 nginx rtmp 流媒体服务器 安装环境说明 系统环境: Centos 7 机型: DELL R540 准备工作 nginx 添加模块,编译安装 nginx ,下载 nginx-rtm ...

  2. 搭建Nginx+rtmp直播服务器

    目录 安装搭建 lnmp 环境 安装 Nginx 的扩展模块 关闭 nginx.php-fpm 服务 查看 nginx 配置参数 重新编译 nginx Centos7 端口开放 查看防火墙状态 开启防 ...

  3. 2021最新 阿里云ECS搭建我的世界服务器

    1. 购买阿里云服务 1.1 选择系统 5人以下纯净服1核2G够用 少量mod推荐2核4G,mod越多内存越高越好 1M带宽在不修改服务器默认视野的情况下足够10人使用系统镜像选择时记得选择ubunt ...

  4. Windows搭建Nginx直播推流服务器

    转载请以链接形式标明出处: 本文出自:103style的博客 目录 资源下载 配置环境变量 检查Nginx 是否能成功启动 修改 Nginx 配置 推流测试 关闭 Nginx 资源下载 将下述资源下载 ...

  5. win7系统搭建流媒体服务器,windows7 下 搭建 nginx + rtmp 流媒体服务器

    成果分享:https://github.com/ziq358/Nginx-Rtmp 材料准备: 1.Microsoft Visual Studio 2010 下载安装. 2.MinGW 安装. 3.下 ...

  6. php对接AliGenie天猫精灵服务器控制智能硬件esp8266① 在阿里云购买搭建私有云服务器,配置 SSL 证书 ,做好准备工作!

    本系列博客学习由非官方人员 半颗心脏 潜心所力所写,仅仅做个人技术交流分享,不做任何商业用途.如有不对之处,请留言,本人及时更改. 1. php对接AliGenie天猫精灵服务器控制智能硬件esp82 ...

  7. linux 搭建nginx + rtmp服务器

    linux 搭建nginx + rtmp服务器 一  环境准备 虚拟机ubuntu 装备,安装一些nginx 必要的依赖和服务 sudo apt-get install libpcre3 libpcr ...

  8. Ubuntu18.04搭建nginx rtmp服务器

    1.前言 系统:ubuntu18.04 安装所需要软件下载地址: https://download.csdn.net/download/u010798513/22847289 2. 安装prce 安装 ...

  9. armlinux 搭建nginx + rtmp服务器

    1 综合篇 点我 2 uboot移植 点我 3 uboot lcd驱动 点我 4 kernel移植 点我 5 kernel lcd驱动 点我 6 摄像头驱动 点我 7 ubuntu base移植 点我 ...

最新文章

  1. CentOS7启动图形界面
  2. 栈与队列3——用递归和栈操作逆序一个栈
  3. OEM中无法用sys用户登录
  4. android自动化框架简要剖析(一):运行原理+基本框架
  5. 谷歌修复4个已遭利用的安卓 0day
  6. react-native 适配问题
  7. 蓝桥杯c语言基础试题答案,2014年蓝桥杯c语言试题及答案
  8. rollup函数(分组后对每组数据分别合计)
  9. 【贪吃蛇C语言版源代码(推荐使用Dev-C++)——附运行截图】
  10. CNN 卷积神经网络-- 残差计算
  11. 图神经网络的图网络学习(上)
  12. 融合知识图谱的电影推荐_算法与交互界面的实现
  13. 汇川伺服设置力矩并报警
  14. Python choice() 函数语法及参数介绍
  15. xp服务器修改登录密码,xp服务器开机密码设置
  16. html5画图作品,10款最佳HTML5绘图工具
  17. 一.Duilib开发之基本使用
  18. 香橙派Pi5基于Qt5视频硬编码编译
  19. 你根本不会用搜索引擎
  20. 微软的某些东西,确实不敢恭维,其实,它可以做得更好

热门文章

  1. quartus Error (12157)解决办法
  2. [美赛F奖][数学建模][经验贴]2021美赛F奖的那些事
  3. 教程 | 如何使用U盘制作启动盘重装Windows系统?
  4. 计算机工程的突出技能该怎么写,没有科研竞赛,计算机保研简历应该怎么写?...
  5. uni-app 封装组件中点击事件及父子组件传值
  6. .npy .npz 文件-numpy的文件存储
  7. 中文Stable Diffusion模型太乙使用教程
  8. sklearn 笔记:高斯过程
  9. 关于浙政钉、专有钉钉的数据埋点小心得总结(稳定性监控、流量分析)
  10. TC275——05ASCLIN-UART