nginx+ffmpeg搭建windows流媒体服务器

准备工具:

nginx

https://download.csdn.net/download/qiuzhihzy123/12433785

ffmpeg

https://download.csdn.net/download/qiuzhihzy123/12433785

下载nginx后,解压nginx,然后修改conf/nginx-win.conf的内容为自己需要的配置,具体如下:

  1. #user  nobody;
  2. # multiple workers works !
  3. worker_processes  2;
  4.  
  5. #error_log  logs/error.log;
  6. #error_log  logs/error.log  notice;
  7. #error_log  logs/error.log  info;
  8.  
  9. #pid        logs/nginx.pid;
  10.  
  11.  
  12. events {
  13.     worker_connections  8192;
  14.     # max value 32768, nginx recycling connections+registry optimization = 
  15.     #   this.value * 20 = max concurrent connections currently tested with one worker
  16.     #   C1000K should be possible depending there is enough ram/cpu power
  17.     # multi_accept on;
  18. }
  19.  
  20.  
  21. http {
  22.     #include      /nginx/conf/naxsi_core.rules;
  23.     include       mime.types;
  24.     default_type  application/octet-stream;
  25.  
  26.     #log_format  main  '$remote_addr:$remote_port - $remote_user [$time_local] "$request" '
  27.     #                  '$status $body_bytes_sent "$http_referer" '
  28.     #                  '"$http_user_agent" "$http_x_forwarded_for"';
  29.  
  30.     #access_log  logs/access.log  main;
  31.  
  32. #     # loadbalancing PHP
  33. #     upstream myLoadBalancer {
  34. #         server 127.0.0.1:9001 weight=1 fail_timeout=5;
  35. #         server 127.0.0.1:9002 weight=1 fail_timeout=5;
  36. #         server 127.0.0.1:9003 weight=1 fail_timeout=5;
  37. #         server 127.0.0.1:9004 weight=1 fail_timeout=5;
  38. #         server 127.0.0.1:9005 weight=1 fail_timeout=5;
  39. #         server 127.0.0.1:9006 weight=1 fail_timeout=5;
  40. #         server 127.0.0.1:9007 weight=1 fail_timeout=5;
  41. #         server 127.0.0.1:9008 weight=1 fail_timeout=5;
  42. #         server 127.0.0.1:9009 weight=1 fail_timeout=5;
  43. #         server 127.0.0.1:9010 weight=1 fail_timeout=5;
  44. #         least_conn;
  45. #     }
  46.  
  47.     sendfile        off;
  48.     #tcp_nopush     on;
  49.  
  50.     server_names_hash_bucket_size 128;
  51.  
  52. ## Start: Timeouts ##
  53.     client_body_timeout   10;
  54.     client_header_timeout 10;
  55.     keepalive_timeout     30;
  56.     send_timeout          10;
  57.     keepalive_requests    10;
  58. ## End: Timeouts ##
  59.  
  60.     #gzip  on;
  61.  
  62.     server {
  63.         listen       80;
  64.         server_name  localhost;
  65.  
  66.         #charset koi8-r;
  67.  
  68.         #access_log  logs/host.access.log  main;
  69.  
  70.         ## Caching Static Files, put before first location
  71.         #location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
  72.         #    expires 14d;
  73.         #    add_header Vary Accept-Encoding;
  74.         #}
  75.  
  76. # For Naxsi remove the single # line for learn mode, or the ## lines for full WAF mode
  77.         location / {
  78.             #include    /nginx/conf/mysite.rules; # see also http block naxsi include line
  79.             ##SecRulesEnabled;
  80.               ##DeniedUrl "/RequestDenied";
  81.               ##CheckRule "$SQL >= 8" BLOCK;
  82.               ##CheckRule "$RFI >= 8" BLOCK;
  83.               ##CheckRule "$TRAVERSAL >= 4" BLOCK;
  84.               ##CheckRule "$XSS >= 8" BLOCK;
  85.             root   html;
  86.             index  index.html index.htm;
  87.         }
  88.  
  89. # For Naxsi remove the ## lines for full WAF mode, redirect location block used by naxsi
  90.         ##location /RequestDenied {
  91.         ##    return 412;
  92.         ##}
  93.  
  94. ## Lua examples !
  95. #         location /robots.txt {
  96. #           rewrite_by_lua '
  97. #             if ngx.var.http_host ~= "localhost" then
  98. #               return ngx.exec("/robots_disallow.txt");
  99. #             end
  100. #           ';
  101. #         }
  102.  
  103.         #error_page  404              /404.html;
  104.  
  105.         # redirect server error pages to the static page /50x.html
  106.         #
  107.         error_page   500 502 503 504  /50x.html;
  108.         location = /50x.html {
  109.             root   html;
  110.         }
  111.  
  112.         # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  113.         #
  114.         #location ~ \.php$ {
  115.         #    proxy_pass   http://127.0.0.1;
  116.         #}
  117.  
  118.         # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  119.         #
  120.         #location ~ \.php$ {
  121.         #    root           html;
  122.         #    fastcgi_pass   127.0.0.1:9000; # single backend process
  123.         #    fastcgi_pass   myLoadBalancer; # or multiple, see example above
  124.         #    fastcgi_index  index.php;
  125.         #    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
  126.         #    include        fastcgi_params;
  127.         #}
  128.  
  129.         # deny access to .htaccess files, if Apache's document root
  130.         # concurs with nginx's one
  131.         #
  132.         #location ~ /\.ht {
  133.         #    deny  all;
  134.         #}
  135.     }
  136.  
  137.  
  138.     # another virtual host using mix of IP-, name-, and port-based configuration
  139.     #
  140.     #server {
  141.     #    listen       8000;
  142.     #    listen       somename:8080;
  143.     #    server_name  somename  alias  another.alias;
  144.  
  145.     #    location / {
  146.     #        root   html;
  147.     #        index  index.html index.htm;
  148.     #    }
  149.     #}
  150.  
  151.  
  152.     # HTTPS server
  153.     #
  154.     #server {
  155.     #    listen       443 ssl spdy;
  156.     #    server_name  localhost;
  157.  
  158.     #    ssl                  on;
  159.     #    ssl_certificate      cert.pem;
  160.     #    ssl_certificate_key  cert.key;
  161.  
  162.     #    ssl_session_timeout  5m;
  163.  
  164.     #    ssl_prefer_server_ciphers On;
  165.     #    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  166.     #    ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:ECDH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!eNULL:!MD5:!DSS:!EXP:!ADH:!LOW:!MEDIUM;
  167.  
  168.     #    location / {
  169.     #        root   html;
  170.     #        index  index.html index.htm;
  171.     #    }
  172.     #}
  173.     
  174.     
  175.  
  176. }
  177.  
  178. rtmp{
  179.     server{
  180.     listen 1935;
  181.     chunk_size 4000;
  182.     application live{
  183.             live on;
  184.             allow play all;
  185.         }
  186.     }
  187. }

只需要修改文件最后的rtmp内容,这里可以更改端口为你自己想要的端口,然后,保存。

启动cmd,进入nginx目录,输入nginx -c conf/nginx-win.conf,具体如下:

 

nginx+ffmpeg搭建windows流媒体服务器_第1张图片

再启动一个cmd,进入ffmpeg目录,执行ffmpeg推流命令如下:

ffmpeg.exe -re -i D:/c.mp4 -f flv rtmp://localhost:1935/live

nginx+ffmpeg搭建windows流媒体服务器_第2张图片

再启动一个cmd,进入ffmpeg目录,启动ffplay,rtmp拉流,命令如下:

ffplay rtmp://localhost:1935/live

具体如下:

nginx+ffmpeg搭建windows流媒体服务器_第3张图片

到此,rtmp流媒体服务器搭建完成,推流和拉流一切正常工作。

你可能感兴趣的:(服务器配置,C#)