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

简介: 阿里云服务器搭建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


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


我是加班猿,我们下期见

相关实践学习
2分钟自动化部署人生模拟器
本场景将带你借助云效流水线Flow实现人生模拟器小游戏的自动化部署
7天玩转云服务器
云服务器ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,可降低 IT 成本,提升运维效率。本课程手把手带你了解ECS、掌握基本操作、动手实操快照管理、镜像管理等。了解产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
5天前
|
人工智能 负载均衡 数据可视化
阿里云出手了,DeepSeek服务器拒绝繁忙,免费部署DeepSeek模型671B满血版
阿里云推出免费部署DeepSeek模型671B满血版服务,通过百炼大模型平台,用户无需编码,最快5分钟、最低0元即可完成部署。平台提供100万免费Token,支持DeepSeek-R1和DeepSeek-V3等多款模型调用,有效解决服务器繁忙问题。新手零基础也能轻松上手,享受高效稳定的API调用和自动弹性扩展功能。教程涵盖开通服务、获取API-KEY及配置Chatbox客户端等步骤,详细指引助您快速实现DeepSeek自由。
72 18
|
1天前
|
Kubernetes 监控 Serverless
基于阿里云Serverless Kubernetes(ASK)的无服务器架构设计与实践
无服务器架构(Serverless Architecture)在云原生技术中备受关注,开发者只需专注于业务逻辑,无需管理服务器。阿里云Serverless Kubernetes(ASK)是基于Kubernetes的托管服务,提供极致弹性和按需付费能力。本文深入探讨如何使用ASK设计和实现无服务器架构,涵盖事件驱动、自动扩展、无状态设计、监控与日志及成本优化等方面,并通过图片处理服务案例展示具体实践,帮助构建高效可靠的无服务器应用。
|
12天前
|
机器学习/深度学习 人工智能 程序员
阿里云出手DeepSeek拒绝服务器繁忙,程序员直呼:真香!
阿里云PAI平台支持一键部署DeepSeek-V3和DeepSeek-R1大模型,用户无需编写代码即可完成从训练到部署的全过程。通过PAI Model Gallery,开发者可轻松选择并部署所需模型版本,享受高效、便捷的AI开发体验。教程详细介绍了开通PAI、选择模型及一键部署的具体步骤,帮助用户快速上手。
|
1天前
|
安全 JavaScript 测试技术
阿里云轻量应用服务器38元1年性能、适用场景简单测评
在阿里云目前的活动中,轻量云服务器2核2G200M峰值带宽每天10点和15点抢购价只要38元一年,e实例云服务器2核2G3M带宽99元1年,u1实例2核4G5M带宽199元一年。其中,阿里云轻量应用服务器38元1年的抢购价,让不少用户心动不已。那么,这款特价轻量应用服务器到底怎么样?是否值得购买呢?本文将从配置、性能、适用场景、价格优势等多个方面对这款轻量应用服务器做个介绍,以供参考。
阿里云轻量应用服务器38元1年性能、适用场景简单测评
|
7天前
|
人工智能 负载均衡 数据可视化
阿里云出手了,基于百炼一键部署DeepSeek满血版,告别服务器繁忙1
阿里云百炼平台推出一键部署DeepSeek-R1满血版671B模型,提供100万免费Token,无需编码,新手5分钟内即可完成部署。通过Chatbox客户端配置API,轻松实现模型调用,解决服务器繁忙问题,支持自动弹性扩展,降低硬件成本。详情及教程见阿里云百炼官网。
168 5
|
7天前
|
存储 安全 网络安全
阿里云国际站:阿里云服务器端口配置
悟空云@CloudWuKong阿里云是全球领先的云计算服务提供商,为用户提供弹性计算、数据库、存储、网络安全等一系列云计算服务。在使用阿里云服务器时,合理配置端口非常重要,可以提高服务器安全性和稳定性。
|
7天前
|
应用服务中间件 PHP nginx
当你的nginx服务器和php服务器不在一起的时候,这个nginx 的root目录问题
两个服务器的网站代码目录需要对齐,docker容器里面也是一样
|
13天前
|
机器学习/深度学习 存储 弹性计算
阿里云gpu云服务器租用价格:最新收费标准及活动价格参考
阿里云gpu云服务器多少钱?A10卡GN7i GPU云服务器32核188G3213.99/1个月起,V100卡GN6v GPU云服务器8核32G3830.00/1个月起,阿里云GPU云服务器是基于GPU应用的计算服务,多适用于视频解码,图形渲染,深度学习,科学计算等应用场景,该产品具有超强计算能力、网络性能出色、购买方式灵活、高性能实例存储( GA1和GN5特有)等特点。下面小编来介绍下阿里云gpu云服务器最新的收费标准及活动价格。
|
2天前
|
存储 弹性计算 人工智能
阿里云轻量应用服务器全球上新!
阿里云轻量应用服务器全球上新!
27 0
|
弹性计算 安全 应用服务中间件
ECS动手搭建Nginx
在ECS的centos7上搭建一个Nginx
2116 7
ECS动手搭建Nginx