零成本搭建自己的RTMP流媒体服务器
使用试用版的云服务器搭载nginx,实现零成本搭建自己的RTMP流媒体服务器
操作方法
- 01
登录云平台,进入控制台,消息里查看登录密码
- 02
通过windows远程桌面直接访问并登录云服务器
- 03
下载nginx开源包和插件 下载链接: http://nginx-win.ecsds.eu/download/nginx 1.7.11.3 Gryphon.zip 下载链接: https://github.com/arut/nginx-rtmp-module/releases 下载v1.2.0版zip格式 下载下来后,将nginx 1.7.11.3 Gryphon解压后的目录名改成nginx-1.7.11.3-Gryphon (这里我是放到C:\nginx-1.7.11.3-Gryphon的),nginx-rtmp-module文件解压后放到C:\nginx-1.7.11.3-Gryphon\nginx-rtmp-module
- 04
这个时候搭建工作基本已经完成了,剩下的就是修改配置了,但是在此之前我们还需要下载msvcr100.dll这个文件,因为在运行的时候会出现提示缺少这个文件无法运行的提示。 只要下载好这个文件,x64版本的放到C:\WINDOWS\SYSTEM32下,x86版本放到C:\WINDOWS\SYSWOW64下,接着重启系统。 下面来修改conf配置文件(配置文件位于C:\nginx-1.7.11.3-Gryphon\conf下) 复制nginx-win.conf文件,修改名称为nginx.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; # } #}}
- 05
最后启动nginx服务,双击目录下的nginx.exe 这里介绍一下CMD命令窗口下nginx的使用命令: (1)启动: start nginx 或 nginx.exe 注:建议使用第一种,第二种会使你的cmd窗口一直处于执行中,不能进行其他命令操作。 (2)停止: nginx.exe -s stop stop是快速停止nginx,可能并不保存相关信息; nginx.exe -s quit quit是完整有序的停止nginx,并保存相关信息。 (3)重新载入Nginx: nginx.exe -s reload 当配置信息修改,需要重新载入这些配置时使用此命令。 (4)重新打开日志文件: nginx.exe -s reopen (5)查看Nginx版本: nginx -v
- 06
好了,现在RTMP服务器已经搭建完成并开启,我们来试试效果吧。 到这里,小伙伴们就要问了,服务器是搭建好了,那推流地址在哪里呢? 别急,我现在就来说明一下: Nginx的推流地址格式为:rtmp://云服务器公网IP地址/live/xxxxx(这里的xxxxx为任意字符) 其中要重点说一下live,这里的live就是conf配置文件中的application后面的字符,可以任意修改,这里的意思相当于live为直播应用,而xxxxx为直播应用下的房间,可以有很多个。 当然nginx的功能并不只有rtmp这么简单,可以定制修改的参数也还有很多,这些就有待小伙伴们搭建好自己的服务器后自行探索了。
- 07
来两发效果图炫耀一下o(*^@^*)o 左图是使用手机推流软件推流到RTMP服务器地址,右图是直接用VLC播放器网络串流下来的画面