nginx.conf 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #daemon off;
  2. error_log /dev/stdout info;
  3. events {
  4. worker_connections 1024;
  5. }
  6. rtmp {
  7. server {
  8. listen ${RTMP_PORT};
  9. chunk_size 4000;
  10. application stream {
  11. live on;
  12. exec ffmpeg -i rtmp://localhost:1935/stream/$name
  13. # 4K (2160p) - 比特率设置为 20Mbps
  14. -c:a libfdk_aac -b:a 192k -c:v libx264 -b:v 20000k -f flv -g 60 -r 60 -s 3840x2160 -preset superfast -profile:v high rtmp://localhost:1935/hls/$name_2160p20000kbs
  15. # 2K (1440p) - 比特率设置为 12Mbps
  16. -c:a libfdk_aac -b:a 192k -c:v libx264 -b:v 12000k -f flv -g 60 -r 60 -s 2560x1440 -preset superfast -profile:v high rtmp://localhost:1935/hls/$name_1440p12000kbs
  17. # 1080p - 比特率设置为 6Mbps
  18. -c:a libfdk_aac -b:a 192k -c:v libx264 -b:v 6000k -f flv -g 60 -r 60 -s 1920x1080 -preset superfast -profile:v high rtmp://localhost:1935/hls/$name_1080p6000kbs
  19. # 720p
  20. -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 2500k -f flv -g 30 -r 30 -s 1280x720 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_720p2628kbs
  21. # 480p
  22. -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 1000k -f flv -g 30 -r 30 -s 854x480 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_480p1128kbs
  23. # 360p
  24. -c:a libfdk_aac -b:a 128k -c:v libx264 -b:v 750k -f flv -g 30 -r 30 -s 640x360 -preset superfast -profile:v baseline rtmp://localhost:1935/hls/$name_360p878kbs;
  25. }
  26. application hls {
  27. live on;
  28. hls on;
  29. hls_fragment_naming system;
  30. hls_fragment 5;
  31. hls_playlist_length 10;
  32. hls_path /opt/data/hls;
  33. hls_nested on;
  34. # 添加新的分辨率变体
  35. hls_variant _2160p20000kbs BANDWIDTH=20192000,RESOLUTION=3840x2160;
  36. hls_variant _1440p12000kbs BANDWIDTH=12192000,RESOLUTION=2560x1440;
  37. hls_variant _1080p6000kbs BANDWIDTH=6192000,RESOLUTION=1920x1080;
  38. hls_variant _720p2628kbs BANDWIDTH=2628000,RESOLUTION=1280x720;
  39. hls_variant _480p1128kbs BANDWIDTH=1128000,RESOLUTION=854x480;
  40. hls_variant _360p878kbs BANDWIDTH=878000,RESOLUTION=640x360;
  41. }
  42. }
  43. }
  44. http {
  45. include mime.types;
  46. default_type application/octet-stream;
  47. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  48. '$status $body_bytes_sent "$http_referer" '
  49. '"$http_user_agent" "$http_x_forwarded_for"';
  50. access_log /dev/stdout main;
  51. root /www/static;
  52. sendfile off;
  53. tcp_nopush on;
  54. server_tokens off;
  55. # 安全设置
  56. add_header X-Frame-Options "SAMEORIGIN";
  57. add_header X-XSS-Protection "1; mode=block";
  58. add_header X-Content-Type-Options "nosniff";
  59. # 超时设置
  60. client_body_timeout 12;
  61. client_header_timeout 12;
  62. keepalive_timeout 65;
  63. server {
  64. listen ${HTTP_PORT};
  65. location /hls {
  66. types {
  67. application/vnd.apple.mpegurl m3u8;
  68. video/mp2t ts;
  69. }
  70. root /opt/data;
  71. add_header Cache-Control no-cache;
  72. add_header Access-Control-Allow-Origin *;
  73. }
  74. location /live {
  75. alias /opt/data/hls;
  76. types {
  77. application/vnd.apple.mpegurl m3u8;
  78. video/mp2t ts;
  79. }
  80. add_header Cache-Control no-cache;
  81. add_header Access-Control-Allow-Origin *;
  82. }
  83. location /stat {
  84. rtmp_stat all;
  85. rtmp_stat_stylesheet stat.xsl;
  86. }
  87. location /stat.xsl {
  88. root /www/static;
  89. }
  90. location = /healthcheck {
  91. access_log off;
  92. add_header Content-Type text/plain;
  93. return 200 'ok';
  94. allow 127.0.0.1;
  95. deny all;
  96. }
  97. location /crossdomain.xml {
  98. default_type text/xml;
  99. expires 24h;
  100. }
  101. }
  102. }