nginx.conf 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. worker_processes 1;
  2. error_log /usr/local/nginx/logs/error.log warn;
  3. pid /var/run/nginx.pid;
  4. events {
  5. worker_connections 1024;
  6. }
  7. http {
  8. include mime.types;
  9. default_type application/octet-stream;
  10. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  11. '$status $body_bytes_sent "$http_referer" '
  12. '"$http_user_agent" "$http_x_forwarded_for"';
  13. access_log /usr/local/nginx/logs/access.log main;
  14. sendfile on;
  15. keepalive_timeout 65;
  16. gzip on;
  17. gzip_comp_level 6;
  18. gzip_types text/plain text/css application/json application/x-javascript application/javascript text/javascript image/svg+xml image/x-icon image/bmp image/png image/gif image/jpeg image/jpg;
  19. gzip_proxied no-cache no-store private expired auth;
  20. gzip_vary on;
  21. upstream frigate_api {
  22. server localhost:5001;
  23. keepalive 1024;
  24. }
  25. upstream jsmpeg {
  26. server localhost:8082;
  27. keepalive 1024;
  28. }
  29. server {
  30. listen 5000;
  31. # vod settings
  32. vod_base_url '';
  33. vod_segments_base_url '';
  34. vod_mode mapped;
  35. vod_max_mapping_response_size 1m;
  36. vod_upstream_location /api;
  37. # vod caches
  38. vod_metadata_cache metadata_cache 512m;
  39. vod_mapping_cache mapping_cache 5m;
  40. # gzip manifests
  41. gzip on;
  42. gzip_types application/vnd.apple.mpegurl;
  43. # file handle caching / aio
  44. open_file_cache max=1000 inactive=5m;
  45. open_file_cache_valid 2m;
  46. open_file_cache_min_uses 1;
  47. open_file_cache_errors on;
  48. aio on;
  49. location /vod/ {
  50. vod hls;
  51. add_header Access-Control-Allow-Headers '*';
  52. add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
  53. add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
  54. add_header Access-Control-Allow-Origin '*';
  55. expires -1;
  56. }
  57. location /stream/ {
  58. add_header 'Cache-Control' 'no-cache';
  59. add_header 'Access-Control-Allow-Origin' "$http_origin" always;
  60. add_header 'Access-Control-Allow-Credentials' 'true';
  61. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  62. if ($request_method = 'OPTIONS') {
  63. add_header 'Access-Control-Allow-Origin' "$http_origin";
  64. add_header 'Access-Control-Max-Age' 1728000;
  65. add_header 'Content-Type' 'text/plain charset=UTF-8';
  66. add_header 'Content-Length' 0;
  67. return 204;
  68. }
  69. types {
  70. application/dash+xml mpd;
  71. application/vnd.apple.mpegurl m3u8;
  72. video/mp2t ts;
  73. image/jpeg jpg;
  74. }
  75. root /tmp;
  76. }
  77. location /clips/ {
  78. add_header 'Access-Control-Allow-Origin' "$http_origin" always;
  79. add_header 'Access-Control-Allow-Credentials' 'true';
  80. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  81. if ($request_method = 'OPTIONS') {
  82. add_header 'Access-Control-Allow-Origin' "$http_origin";
  83. add_header 'Access-Control-Max-Age' 1728000;
  84. add_header 'Content-Type' 'text/plain charset=UTF-8';
  85. add_header 'Content-Length' 0;
  86. return 204;
  87. }
  88. types {
  89. video/mp4 mp4;
  90. image/jpeg jpg;
  91. }
  92. autoindex on;
  93. root /media/frigate;
  94. }
  95. location /recordings/ {
  96. add_header 'Access-Control-Allow-Origin' "$http_origin" always;
  97. add_header 'Access-Control-Allow-Credentials' 'true';
  98. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  99. if ($request_method = 'OPTIONS') {
  100. add_header 'Access-Control-Allow-Origin' "$http_origin";
  101. add_header 'Access-Control-Max-Age' 1728000;
  102. add_header 'Content-Type' 'text/plain charset=UTF-8';
  103. add_header 'Content-Length' 0;
  104. return 204;
  105. }
  106. types {
  107. video/mp4 mp4;
  108. }
  109. autoindex on;
  110. autoindex_format json;
  111. root /media/frigate;
  112. }
  113. location /ws {
  114. proxy_pass http://frigate_api/ws;
  115. proxy_http_version 1.1;
  116. proxy_set_header Upgrade $http_upgrade;
  117. proxy_set_header Connection "Upgrade";
  118. proxy_set_header Host $host;
  119. }
  120. location /live/ {
  121. proxy_pass http://jsmpeg/;
  122. proxy_http_version 1.1;
  123. proxy_set_header Upgrade $http_upgrade;
  124. proxy_set_header Connection "Upgrade";
  125. proxy_set_header Host $host;
  126. }
  127. location /api/ {
  128. add_header 'Access-Control-Allow-Origin' '*';
  129. add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
  130. add_header Cache-Control "no-store";
  131. proxy_pass http://frigate_api/;
  132. proxy_pass_request_headers on;
  133. proxy_set_header Host $host;
  134. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  135. proxy_set_header X-Forwarded-Proto $scheme;
  136. }
  137. location / {
  138. add_header Cache-Control "no-cache";
  139. location ~* \.(?:js|css|svg|ico|png)$ {
  140. access_log off;
  141. expires 1y;
  142. add_header Cache-Control "public";
  143. }
  144. sub_filter 'href="/' 'href="$http_x_ingress_path/';
  145. sub_filter 'url(/' 'url($http_x_ingress_path/';
  146. sub_filter '"/dist/' '"$http_x_ingress_path/dist/';
  147. sub_filter '"/js/' '"$http_x_ingress_path/js/';
  148. sub_filter '<body>' '<body><script>window.baseUrl="$http_x_ingress_path";</script>';
  149. sub_filter_types text/css application/javascript;
  150. sub_filter_once off;
  151. root /opt/frigate/web;
  152. try_files $uri $uri/ /index.html;
  153. }
  154. }
  155. }
  156. rtmp {
  157. server {
  158. listen 1935;
  159. chunk_size 4096;
  160. allow publish 127.0.0.1;
  161. deny publish all;
  162. allow play all;
  163. application live {
  164. live on;
  165. record off;
  166. meta copy;
  167. }
  168. }
  169. }