nginx.conf 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. worker_processes auto;
  2. error_log /dev/stdout info;
  3. events {
  4. worker_connections 1024;
  5. }
  6. # RTMPS configuration
  7. stream {
  8. upstream backend {
  9. server 127.0.0.1:1935;
  10. }
  11. server {
  12. listen 1936 ssl;
  13. proxy_pass backend;
  14. ssl_certificate /ssl/self_signed/rtmp.crt;
  15. ssl_certificate_key /ssl/self_signed/rtmp.key;
  16. }
  17. }
  18. # RTMP configuration
  19. rtmp {
  20. server {
  21. listen 1935;
  22. chunk_size 4000;
  23. # This application is to accept incoming stream
  24. application live {
  25. # Allows live input
  26. live on;
  27. # Drop Publishing connections that havnt sent any stream data for over 10 seconds
  28. drop_idle_publisher 10s;
  29. # Local push for built in players
  30. push rtmp://localhost:1935/show;
  31. }
  32. # This is the HLS application
  33. application show {
  34. # Allows live input from above application
  35. live on;
  36. # Disable consuming the stream from nginx as rtmp
  37. deny play all;
  38. # Enable HTTP Live Streaming
  39. hls on;
  40. hls_fragment 3;
  41. hls_playlist_length 20;
  42. hls_path /mnt/hls/; # hls fragments path
  43. }
  44. }
  45. }
  46. # HTTP configuration
  47. http {
  48. sendfile off;
  49. tcp_nopush on;
  50. access_log /dev/stdout combined;
  51. directio 512;
  52. ssl_protocols TLSv1.2 TLSv1.3;
  53. ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
  54. ssl_prefer_server_ciphers off;
  55. ssl_session_cache shared:SSL:10m;
  56. ssl_session_timeout 1d;
  57. # HTTP server required to serve the player and HLS fragments
  58. server {
  59. listen 8080;
  60. listen 8443 ssl;
  61. ssl_certificate /ssl/self_signed/rtmp.crt;
  62. ssl_certificate_key /ssl/self_signed/rtmp.key;
  63. # Redirect requests for http://<server_ip>:8080/ to http://<server_ip>:8080/player
  64. location = / {
  65. # This is required to handle reverse proxy's like NginxProxyManager, otherwise the redirect will
  66. # include this servers port in the redirect.
  67. absolute_redirect off;
  68. return 302 /player.html;
  69. }
  70. # Serve HLS fragments
  71. location /hls {
  72. types {
  73. application/vnd.apple.mpegurl m3u8;
  74. video/mp2t ts;
  75. }
  76. root /mnt;
  77. # Disable cache
  78. add_header Cache-Control no-cache;
  79. # CORS setup
  80. add_header 'Access-Control-Allow-Origin' '*' always;
  81. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  82. # allow CORS preflight requests
  83. if ($request_method = 'OPTIONS') {
  84. add_header 'Access-Control-Allow-Origin' '*';
  85. add_header 'Access-Control-Max-Age' 1728000;
  86. add_header 'Content-Type' 'text/plain charset=UTF-8';
  87. add_header 'Content-Length' 0;
  88. return 204;
  89. }
  90. }
  91. # This URL provides RTMP statistics in XML
  92. location /stat {
  93. rtmp_stat all;
  94. # Use stat.xsl stylesheet
  95. rtmp_stat_stylesheet stat.xsl;
  96. }
  97. location /stat.xsl {
  98. # XML stylesheet to view RTMP stats.
  99. root /usr/local/nginx/html;
  100. }
  101. }
  102. }