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

本文涉及的产品
云服务器 ECS,u1 2核4GB 3个月
云服务器 ECS,u1 4核8GB 1个月
云服务器 ECS,每月免费额度200元 3个月
简介: 阿里云服务器搭建Nginx+rtmp推流服务器

一、前期准备


服务器操作系统: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


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


1.png


重启ngxin服务


sudo systemctl restart nginx


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


2.png


四、测试


1.下载OBS-Studio


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


2.下载VLC


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


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


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


3.png


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


4.png


4.VLC拉流


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


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


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


5.png


如果你觉得文章还不错,可以给个"三连"


我是加班猿,我们下期见

相关实践学习
一小时快速掌握 SQL 语法
本实验带您学习SQL的基础语法,快速入门SQL。
7天玩转云服务器
云服务器ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,可降低 IT 成本,提升运维效率。本课程手把手带你了解ECS、掌握基本操作、动手实操快照管理、镜像管理等。了解产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
1天前
|
弹性计算 安全 Shell
阿里云ECS安全加固:从访问控制到数据保护的全方位策略
【6月更文挑战第29天】阿里云ECS安全聚焦访问控制、系统加固及数据保护。安全组限定IP和端口访问,密钥对增强SSH登录安全;定期更新补丁,使用防病毒工具;数据备份与加密确保数据安全。多维度策略保障业务安全。
23 15
|
1天前
|
弹性计算
阿里云ECS使用体验
在申请高校学生免费体验阿里云ECS云服务器后的一些使用体验和感受。
|
1天前
|
小程序 数据安全/隐私保护
阿里云新手入门:注册账号、实名认证、申请免费云服务器
阿里云新手指南:注册账号(手机号或支付宝快捷注册),完成实名认证(个人/企业)。通过免费服务器获取3个月试用。创建后,设置密码,远程连接,配置安全组规则,部署应用,如建站与环境安装。详询官方教程。
|
1天前
|
机器学习/深度学习 人工智能 弹性计算
阿里云GPU云服务器介绍_GPU租用费用_GPU优势和使用场景说明
阿里云GPU云服务器提供NVIDIA A10、V100、T4、P4、P100等GPU卡,结合高性能CPU,单实例计算性能高达5PFLOPS。支持多种实例规格,如A10卡GN7i、V100-16G卡GN6v等,应用于深度学习、科学计算等场景。GPU服务器租用费用因实例规格而异,如A10卡GN7i每月3213.99元起。阿里云还提供GPU加速软件如AIACC-Training、AIACC-Inference等。网络性能强大,VPC支持2400万PPS和160Gbps内网带宽。购买方式灵活,包括包年包月、按量付费等。客户案例包括深势科技、流利说和小牛翻译等。
|
1天前
|
存储 弹性计算 网络协议
阿里云hpc8ae服务器ECS高性能计算优化型实例性能详解
阿里云ECS的HPC优化型hpc8ae实例搭载3.75 GHz AMD第四代EPYC处理器,配备64 Gbps eRDMA网络,专为工业仿真、EDA、地质勘探等HPC工作负载设计。实例提供1:4的CPU内存配比,支持ESSD存储和IPv4/IPv6,操作系统限于特定版本的CentOS和Alibaba Cloud Linux。ecs.hpc8ae.32xlarge实例拥有64核和256 GiB内存,网络带宽和eRDMA带宽均为64 Gbit/s。适用于CFD、FEA、气象预报等场景。
|
1天前
|
弹性计算
阿里云ECS的使用心得
本文主要讲述了我是如何了解到ECS,使用ECS的一些经验,以及自己的感悟心得
|
1天前
|
机器学习/深度学习 人工智能 弹性计算
阿里云GPU服务器租用费用_GPU服务器详解_A10、V100、T4、P4、P100
阿里云GPU云服务器提供NVIDIA A10、V100、T4、P4、P100等多种GPU卡,适合深度学习、科学计算等场景。实例性能强劲,单实例可达5PFLOPS混合精度计算,VPC网络支持2400万PPS和160Gbps内网带宽。GPU实例包括A10卡GN7i(3213.99元/月起)、V100-16G卡GN6v(3830.00元/月起)等,价格因配置而异。阿里云还提供GPU加速软件如AIACC-Training和AIACC-Inference,以及弹性计算实例EAIS。客户案例包括深势科技、流利说和小牛翻译等。
|
1天前
|
弹性计算 安全 前端开发
云服务器ECS通用型、计算型和内存型区别以及详细介绍
阿里云ECS实例有计算型(c)、通用型(g)和内存型(r)系列,区别在于CPU内存比。计算型1:2,如2核4G;通用型1:4,如2核8G;内存型1:8,如2核16G。实例有第五代至第八代,如c7、g5、r8a等,新一代通常使用更先进的处理器。性能参数如CPU主频、IOPS和网络带宽随实例规格变化。实例适合场景包括高网络包收发、数据库、计算密集型任务等。
|
1天前
|
弹性计算 安全 前端开发
阿里云服务器ECS通用型、计算型和内存型详细介绍和性能参数表
阿里云ECS实例有计算型(c)、通用型(g)和内存型(r)三种,主要区别在于CPU和内存比例。计算型CPU内存比1:2,如2核4G;通用型为1:4,如2核8G;内存型为1:8,如2核16G。随着技术迭代,有第五代至第八代产品,如c7、g5、r8a等。每代实例在CPU型号和主频上相同,但性能有所提升。实例性能参数包括网络带宽、收发包能力、连接数等。具体应用场景如计算型适合高网络包收发、通用型适合企业级应用,内存型适合内存数据库等。详细信息可参阅阿里云ECS页面。
|
9天前
|
存储 弹性计算 Linux
阿里云账号注册、完成实名认证、试用云服务器和购买云服务器流程参考
本文为大家介绍新手用户从注册阿里云账号,完成实名认证,然后试用云服务器和购买云服务器的主要流程,适合初次购买和试用阿里云服务器的新手用户参考。
阿里云账号注册、完成实名认证、试用云服务器和购买云服务器流程参考

热门文章

最新文章