nginx.conf 6.3 KB

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