ustoopia

default config file for NGINX HLS RTMP streaming

Mar 29th, 2019
3,855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.36 KB | None | 0 0
  1. ##
  2. # You should look at the following URL's in order to grasp a solid understanding
  3. # of Nginx configuration files in order to fully unleash the power of Nginx.
  4. # https://www.nginx.com/resources/wiki/start/
  5. # https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
  6. # https://wiki.debian.org/Nginx/DirectoryStructure
  7. #
  8. # In most cases, administrators will remove this file from sites-enabled/ and
  9. # leave it as reference inside of sites-available where it will continue to be
  10. # updated by the nginx packaging team.
  11. #
  12. # This file will automatically load configuration files provided by other
  13. # applications, such as Drupal or Wordpress. These applications will be made
  14. # available underneath a path with that package name, such as /drupal8.
  15. #
  16. # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
  17. ##
  18.  
  19. # Default server configuration
  20. #
  21. server {
  22. listen 8088 default_server;
  23. # listen [::]:80 default_server;
  24.  
  25. # listen 4438 ssl default_server;
  26. # listen [::]:4438 ssl default_server;
  27. # include snippets/snakeoil.conf;
  28.  
  29. # ssl_certificate /etc/letsencrypt/live/yourserver.ddns.net/fullchain.pem; # managed by Certbot
  30. # ssl_certificate_key /etc/letsencrypt/live/yourserver.ddns.net/privkey.pem; # managed by Certbot
  31.  
  32. root /var/www/html;
  33.  
  34. # Add index.php to the list if you are using PHP
  35. index index.nginx-debian.html index.html index.htm;
  36.  
  37. server_name _;
  38.  
  39. location / {
  40. root /var/www/html;
  41. index index.nginx-debian.html index.html index.htm;
  42. # First attempt to serve request as file, then as directory, then fall back to displaying a 404.
  43. try_files $uri $uri/ =404;
  44. }
  45.  
  46. #location ~ \.php$ {
  47. # include snippets/fastcgi-php.conf;
  48. # # With php-fpm (or other unix sockets):
  49. # fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
  50. # # With php-cgi (or other tcp sockets):
  51. # fastcgi_pass 127.0.0.1:9000;
  52. #}
  53.  
  54. #error_page 500 502 503 504 /50x.html;
  55. #location = /50x.html {
  56. # root /var/www/html;
  57. #}
  58.  
  59. location ~ /\.ht {
  60. deny all;
  61. }
  62.  
  63. #location ~ \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv|mpd|m3u8)$ {
  64. # expires 7d;
  65. # access_log off;
  66. # log_not_found off;
  67. # }
  68. #location ~ \.(?:svgz?|ttf|ttc|otf|eot|woff|woff2)$ {
  69. # add_header Access-Control-Allow-Origin "*";
  70. # expires 7d;
  71. # access_log off;
  72. # }
  73.  
  74. # This provides RTMP statistics in XML at http://your-server-address/stat
  75. location /stat {
  76. rtmp_stat all;
  77. rtmp_stat_stylesheet stat.xsl;
  78. auth_basic "Restricted Content";
  79. auth_basic_user_file /etc/nginx/.htpasswd;
  80. }
  81. # XML stylesheet to view RTMP stats. Copy stat.xsl wherever you want and put the full directory path here
  82. location /stat.xsl {
  83. root /var/www/html/;
  84. }
  85. # Control interface (extremely useful, but can also boot people from streams so we put basic auth in front of it - see https://github.com/arut/nginx-rtmp-module/wiki/Control-module for more information)
  86. # location /control {
  87. # # you'll need a htpasswd auth file, that's outside the scope of this doc but any apache one will work
  88. # auth_basic "stream";
  89. # auth_basic_user_file /etc/nginx/.htpasswd;
  90. # rtmp_control all;
  91. # }
  92.  
  93. # allows us to see how stats on viewers on our Nginx site using a URL like: "http://my-ip/stats"
  94. # location /stub_status {
  95. # stub_status;
  96. # allow 127.0.0.1;
  97. # deny all;
  98. # }
  99. #creates the http-location for our full-resolution (desktop) HLS stream - "http://my-ip/live/my-stream-key/index.m3u8"
  100.  
  101. # ========================================== RTMP =================================== #
  102. location /live {
  103. # root /var/www/;
  104. alias /var/www/hls/live;
  105. expires -1;
  106. autoindex on;
  107. autoindex_localtime on;
  108. # CORS setup #
  109. set $sent_http_accept_ranges bytes;
  110. add_header 'Cache-Control' 'no-cache';
  111. add_header Cache-Control no-cache;
  112. add_header 'Access-Control-Allow-Origin' '*' always;
  113. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  114. # allow CORS preflight requests #
  115. if ($request_method = 'OPTIONS') {
  116. add_header 'Access-Control-Allow-Origin' '*';
  117. add_header 'Access-Control-Max-Age' 1728000;
  118. add_header 'Content-Type' 'text/plain charset=UTF-8';
  119. add_header 'Content-Length' 0;
  120. return 204;
  121. }
  122. types {
  123. application/vnd.apple.mpegurl m3u8;
  124. application/dash+xml mpd;
  125. video/mp2t ts;
  126. }
  127. }
  128.  
  129. location /hls {
  130. root /var/www;
  131. # alias /var/www/hls;
  132. expires -1;
  133. autoindex on;
  134. autoindex_localtime on;
  135. # CORS setup #
  136. set $sent_http_accept_ranges bytes;
  137. add_header Cache-Control no-cache;
  138. add_header 'Access-Control-Allow-Origin' '*' always;
  139. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  140. # allow CORS preflight requests #
  141. if ($request_method = 'OPTIONS') {
  142. add_header 'Access-Control-Allow-Origin' '*';
  143. add_header 'Access-Control-Max-Age' 1728000;
  144. add_header 'Content-Type' 'text/plain charset=UTF-8';
  145. add_header 'Content-Length' 0;
  146. return 204;
  147. }
  148. types {
  149. application/vnd.apple.mpegurl m3u8;
  150. application/dash+xml mpd;
  151. video/mp2t ts;
  152. }
  153. }
  154. # mpeg-dash for HTML5, HTTP side. nginx stores DASH fragments here, so make sure it's writable by nginx
  155. location /dash {
  156. # root /var/www;
  157. alias /var/www/dash;
  158. autoindex on;
  159. autoindex_localtime on;
  160. # CORS setup #
  161. set $sent_http_accept_ranges bytes;
  162. add_header Cache-Control no-cache;
  163. add_header 'Access-Control-Allow-Origin' '*' always;
  164. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  165. # allow CORS preflight requests #
  166. if ($request_method = 'OPTIONS') {
  167. add_header 'Access-Control-Allow-Origin' '*';
  168. add_header 'Access-Control-Max-Age' 1728000;
  169. add_header 'Content-Type' 'text/plain charset=UTF-8';
  170. add_header 'Content-Length' 0;
  171. return 204;
  172. }
  173. types {
  174. application/x-mpegURL m3u8;
  175. application/dash+xml mpd;
  176. video/mp2t ts;
  177. video/mp4 mp4;
  178. }
  179. }
  180. # creates the http-location for our mobile-device HLS stream - "http://my-ip/low/my-stream-key/index.m3u8"
  181. location /low {
  182. # root /var/www/hls;
  183. alias /var/www/hls/low;
  184. expires -1;
  185. autoindex on;
  186. autoindex_localtime on;
  187. # CORS setup #
  188. set $sent_http_accept_ranges bytes;
  189. add_header Cache-Control no-cache;
  190. add_header 'Access-Control-Allow-Origin' '*' always;
  191. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  192. # allow CORS preflight requests #
  193. if ($request_method = 'OPTIONS') {
  194. add_header 'Access-Control-Allow-Origin' '*';
  195. add_header 'Access-Control-Max-Age' 1728000;
  196. add_header 'Content-Type' 'text/plain charset=UTF-8';
  197. add_header 'Content-Length' 0;
  198. return 204;
  199. }
  200. types {
  201. application/vnd.apple.mpegurl m3u8;
  202. application/dash+xml mpd;
  203. video/mp2t ts;
  204. video/mp4 mp4;
  205. }
  206. }
  207.  
  208. location /recordings {
  209. alias /var/www/recordings/;
  210. # root /var/www/recordings;
  211. autoindex on;
  212. autoindex_localtime on;
  213. # CORS setup #
  214. set $sent_http_accept_ranges bytes;
  215. add_header Cache-Control no-cache;
  216. add_header 'Access-Control-Allow-Origin' '*' always;
  217. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  218. # allow CORS preflight requests #
  219. if ($request_method = 'OPTIONS') {
  220. add_header 'Access-Control-Allow-Origin' '*';
  221. add_header 'Access-Control-Max-Age' 1728000;
  222. add_header 'Content-Type' 'text/plain charset=UTF-8';
  223. add_header 'Content-Length' 0;
  224. return 204;
  225. }
  226. types {
  227. application/vnd.apple.mpegurl m3u8;
  228. application/dash+xml mpd;
  229. video/mp2t ts;
  230. video/mp4 mp4;
  231. }
  232. }
  233. }
Add Comment
Please, Sign In to add comment