目录简介和安装

配置

OBS推流

运行

拉流

完成

简介和安装

Nginx 本身是一个非常出色的HTTP服务器,OBS (Open Broadcaster Software) 是一个免费且开源的,全平台支持的视频录制和直播软件。这两个东西通过一个nginx的模块nginx-rtmp-module组合在一起,即可以搭建一个功能流媒体服务器。这个流媒体服务器可以支持RTMP和HLS(Live Http Stream)。

FFmpeg也是一个非常优秀的音视频解决软件。但OBS的界面更加友好,且支持屏幕捕获,所以我选择OBS。其实是因为FFmpeg没有GUI界面,所以我懒得再去研究它。

关于Nginx的安装,可以参考这里。在Linux端的Nginx与RTMP模块的安装,可以参考这里。RTMP模块的Github地址在这里,你可以在这里看到更为详尽的使用说明。

作者在Windows环境下搭建服务器,并且仅仅以最简单的方式实现作者需要的功能。

配置

假定你已经安装好了Nginx和RTMP插件,现在是使用它的时候了。

首先,定义一个Nginx的配置文件nginx-win-rmtp.conf。

展开查看范例

#user nobody;

# multiple workers works !

worker_processes 2;

#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/nginx.pid;

events {

worker_connections 8192;

# max value 32768, nginx recycling connections+registry optimization =

# this.value * 20 = max concurrent connections currently tested with one worker

# C1000K should be possible depending there is enough ram/cpu power

# multi_accept on;

}

rtmp {

server {

listen 1935;

chunk_size 4000;

application live {

live on;

}

}

}

http {

#include /nginx/conf/naxsi_core.rules;

include mime.types;

default_type application/octet-stream;

#log_format main '$remote_addr:$remote_port - $remote_user [$time_local] "$request" '

# '$status $body_bytes_sent "$http_referer" '

# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

# # loadbalancing PHP

# upstream myLoadBalancer {

# server 127.0.0.1:9001 weight=1 fail_timeout=5;

# server 127.0.0.1:9002 weight=1 fail_timeout=5;

# server 127.0.0.1:9003 weight=1 fail_timeout=5;

# server 127.0.0.1:9004 weight=1 fail_timeout=5;

# server 127.0.0.1:9005 weight=1 fail_timeout=5;

# server 127.0.0.1:9006 weight=1 fail_timeout=5;

# server 127.0.0.1:9007 weight=1 fail_timeout=5;

# server 127.0.0.1:9008 weight=1 fail_timeout=5;

# server 127.0.0.1:9009 weight=1 fail_timeout=5;

# server 127.0.0.1:9010 weight=1 fail_timeout=5;

# least_conn;

# }

sendfile off;

#tcp_nopush on;

server_names_hash_bucket_size 128;

## Start: Timeouts ##

client_body_timeout 10;

client_header_timeout 10;

keepalive_timeout 30;

send_timeout 10;

keepalive_requests 10;

## End: Timeouts ##

#gzip on;

server {

listen 80;

server_name localhost;

location /stat {

rtmp_stat all;

rtmp_stat_stylesheet stat.xsl;

}

location /stat.xsl {

root nginx-rtmp-module/;

}

location /control {

rtmp_control all;

}

#charset koi8-r;

#access_log logs/host.access.log main;

## Caching Static Files, put before first location

#location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {

# expires 14d;

# add_header Vary Accept-Encoding;

#}

# For Naxsi remove the single # line for learn mode, or the ## lines for full WAF mode

location / {

#include /nginx/conf/mysite.rules; # see also http block naxsi include line

##SecRulesEnabled;

##DeniedUrl "/RequestDenied";

##CheckRule "$SQL >= 8" BLOCK;

##CheckRule "$RFI >= 8" BLOCK;

##CheckRule "$TRAVERSAL >= 4" BLOCK;

##CheckRule "$XSS >= 8" BLOCK;

root html;

index index.html index.htm;

}

# For Naxsi remove the ## lines for full WAF mode, redirect location block used by naxsi

##location /RequestDenied {

## return 412;

##}

## Lua examples !

# location /robots.txt {

# rewrite_by_lua '

# if ngx.var.http_host ~= "localhost" then

# return ngx.exec("/robots_disallow.txt");

# end

# ';

# }

#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; # single backend process

# fastcgi_pass myLoadBalancer; # or multiple, see example above

# fastcgi_index index.php;

# fastcgi_param SCRIPT_FILENAME $document_root$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;

# }

#}

# HTTPS server

#

#server {

# listen 443 ssl spdy;

# server_name localhost;

# ssl on;

# ssl_certificate cert.pem;

# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_prefer_server_ciphers On;

# ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

# ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:ECDH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!eNULL:!MD5:!DSS:!EXP:!ADH:!LOW:!MEDIUM;

# location / {

# root html;

# index index.html index.htm;

# }

#}

}

挑重点的说,我们需要注意的是

rtmp {

server {

listen 1935;

chunk_size 4000;

application live {

live on;

}

}

}

此处的listen指的是你的rtmp开在了本地的哪个端口,当你需要链接服务器的时候,别忘了把端口号加上,如果设备处于内网,那么记得打开端口映射,防火墙选择放行。因为我们关注的只有rtmp服务器,所以无需关注其他端口。

OBS推流

打开OBS。

1.进入推流设置,将服务设置为“自定义”。

2.服务器设置为rtmp://IP:Port/APP。

3.串流秘钥不填写,作者不会使用权限控制的功能。想要进行权限设置,可以参考这里。

因为在配置文件中我们创建的app名字就叫live,所以在这里APP填写为live。如rtmp://192.168.1.110:1935/live。

运行

我写了一个Powershell脚本来运行nginx。可以在一个PS窗口中非常方便的运行和结束nginx。

该脚本默认nginx-win-rtmp.conf配置文件在nginx.exe目录下的\conf目录中。

而nginx.exe的路径在D:\Hider\Tools\FFmpeg+nginx+LIVE\nginx-1.7.11.3-Gryphon中,请根据实际情况自行修改。

cd "D:\Hider\Tools\FFmpeg+nginx+LIVE\nginx-1.7.11.3-Gryphon"

# 若nginx已经运行,则停止

Get-Process -Name "nginx" | Stop-Process

$job = Start-Job -ScriptBlock {

cd "D:\Hider\Tools\FFmpeg+nginx+LIVE\nginx-1.7.11.3-Gryphon";

.\nginx.exe -c conf\nginx-win-rtmp.conf;

}

Write-Host "Starting...`n"

sleep 2

Get-Job

Write-Host "`n"

Get-Process -Name "nginx" | Format-Table

do {

Write-Host "`nNginx is running, finish it?`n";

$exit = Read-Host "Type Y to finish";

Write-Host "`n"

} while ($exit -ne "Y")

Write-Host "Before:"

Get-Process -Name "nginx" | Format-Table

.\nginx.exe -s quit

# 先平稳关闭,若失败则强制结束进程

Get-Process -Name "nginx" | Stop-Process

sleep 1

Write-Host "`nAfter:"

Get-Process -Name "ngin*" | Format-Table

Write-Host "(It has been finished if there were no output.)"

Write-Host "`nNginx has been finished.`n"

pause

拉流

让OBS开始推流,如果一切都没有问题,此时应该是可以正常运行的。接下来,我们要让客户端拉取直播。

作者使用Potplayer,各个(靠谱的)播放器播放流的方法都大同小异:

1.菜单 - 打开 - 打开流(或 打开链接 等)

2.输入刚刚你推流的rtmp://网址,和OBS推流地址相同。

完成

到此为止,你应该已经成功的在本地搭建了一个简单的nginx直播服务器,并且能够正常观看。

十分感谢您的阅读,这是我第一次写博客,希望能够得到更多的指教,包括技术方面和写作方面的。

来源:https://www.cnblogs.com/zhiders/p/12987517.html

如何自建obs服务器,使用 Nginx+OBS 搭建rmtp直播服务器并进行直播相关推荐

  1. CSGO社区服务器开服架设搭建教程windows服务器什么配置的合适国际服

    CSGO社区服务器开服架设搭建教程windows服务器什么配置的合适国际服 <反恐精英:全球攻势>,原名Counter-Strike: Global Offensive,是一款由VALVE ...

  2. Nginx + PHP 搭建高性能web服务器

    写在前面: 1. Issue: *** 'libmcrypt-config --version' returned 2.4.0, but LIBMCRYPT (2.5.8) *** was found ...

  3. 隐藏web服务器信息,nginx 隐藏版本号与WEB服务器信息的解决方法

    nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看看最终的隐藏结果吧 具体怎么实现呢,其实也很简单,请往下看 1 官网下载最新稳定版 wget http://nginx.org/dow ...

  4. 提供最全面最详细的ESP32从零开始搭建一个物联网平台教程(从最基本的配网和内建WEB服务器开始到自已搭建一个MQTT服务器)

    目录 教程大纲 硬件需求 教程说明 教程章节链接 ESP32搭建WEB服务器一(AP配网) ESP32搭建WEB服务器二(STA模式) ESP32搭建WEB服务器三(AP模式与STA模式共存) ESP ...

  5. sql服务器默认密码_搭建一个DNS服务器,轻松实现域名解析内容分发,访问速度提高N倍...

    DNS服务器,Domain Name Server,域名解析服务器,互联网上相互通信使用的是IP,但是IP是又长又臭又难记,所以创造了域名来解决IP难写难记的问题,记一个g.cn比203.208.50 ...

  6. 调用ice服务器_Nodejs+socket.io搭建WebRTC信令服务器

    前言 我们在学习 WebRTC 时,首先要把实验环境搭建好,这样我们就可以在上面做各种实验了. 对于 WebRTC 来说,它有一整套规范,如使它使用的接口.使用SDP进行媒体协商.通过ICE收集地址并 ...

  7. python打造流媒体服务器_使用Flask搭建一个流媒体服务器

    摘要 收到前不久订阅的PythonWeekly发过来的一个邮件通知,由Miguel写的一篇介绍如何使用Flask搭建一个流媒体服务器的文章,思路很新颖也很有意思.你可以点击这里阅读英文原文.或者跟随本 ...

  8. 咋搭建域控服务器,Active Directory虚拟机搭建域控服务器环境

    前言 还是和上一章一样,痛苦过后还是记录下给后来人提供便利为妙. 虚拟机选择:建议Hyper-V或者VMware 系统选择:建议WIindows Server 2003及以上 我这里是使用VMware ...

  9. nginx 根证书 服务器证书,Nginx双向证书校验(服务器验证客户端证书)

    1.创建Root CA私钥 openssl genrsa -out root-ca.key 1024 2.创建Root CA证书请求 openssl req -new -out root-ca.csr ...

最新文章

  1. Java项目:教务管理系统(java+JSP+Spring+SpringBoot+layui+maven)
  2. WinForm界面设计优化过程
  3. 未来ui设计的发展趋势_2025年的未来UI趋势?
  4. Array的用法总结-swift
  5. 你不可不看的 Oracle RAC 日常基本维护命令
  6. 【janio】janio ClassBodyEvaluator 的使用
  7. sqlserver提权失败_利用mssql模拟登录提权
  8. AAAI2021-基于对比学习的三元组生成式抽取方法
  9. [框架]高并发中的惊群效应(干货多多)
  10. HTRAN 2.4终极使用
  11. Ds918 ds3615 ds3617区别_红、白葡萄酒间真正的区别
  12. 电脑系统win8计算机在哪里设置开机密码,电脑怎样设置开机密码_win8开机密码设置...
  13. Linux查看服务器SN序列码
  14. php phacon 关联模型吗,Phalcon模型
  15. 量化交易之深入理解TB系统运行机制
  16. 解决吉特哈布原本可以访问突然访问不了的问题
  17. 2023高频经典前端面试题(es6+webpack+http网络+性能优化中篇,含答案)
  18. mysql出现表warning_查看mysql的warnings
  19. 学习OpenCV3:Cmake+MinGW编译OpenCV
  20. 虚拟机VMWare Workstation最新官方原版 有效VMware7.1.4序列号 密钥 VMware7.1.4破解版破解方法 VMware7.1

热门文章

  1. 全国计算机四级网络工程师教程,全国计算机等级考试立体化应试教程——四级网络工程师...
  2. 拼多多向1688开枪
  3. 组合数算法的非递归实现
  4. 转区系统开放艾欧尼亚转入服务器,【英雄联盟】转区系统开放艾欧尼亚转入服务...
  5. Data Science 到底是什么?
  6. html中的那些炫酷吊炸天的操作
  7. idea 如何导入和导出自己设置好的主题背景
  8. 我的世界(10)-快速建筑(创世神WorldEdit)
  9. Python小程序之超市买水果
  10. socket整理复习