nginx.conf 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. server {
  26. listen 5000;
  27. # vod settings
  28. vod_mode mapped;
  29. vod_max_mapping_response_size 1m;
  30. vod_upstream_location /api;
  31. vod_last_modified 'Sun, 19 Nov 2000 08:52:00 GMT';
  32. vod_last_modified_types *;
  33. # vod caches
  34. vod_metadata_cache metadata_cache 512m;
  35. vod_response_cache response_cache 128m;
  36. vod_mapping_cache mapping_cache 5m;
  37. # gzip manifests
  38. gzip on;
  39. gzip_types application/vnd.apple.mpegurl;
  40. # file handle caching / aio
  41. open_file_cache max=1000 inactive=5m;
  42. open_file_cache_valid 2m;
  43. open_file_cache_min_uses 1;
  44. open_file_cache_errors on;
  45. aio on;
  46. location /vod/ {
  47. vod hls;
  48. add_header Access-Control-Allow-Headers '*';
  49. add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
  50. add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
  51. add_header Access-Control-Allow-Origin '*';
  52. expires 100d;
  53. }
  54. location /stream/ {
  55. add_header 'Cache-Control' 'no-cache';
  56. add_header 'Access-Control-Allow-Origin' "$http_origin" always;
  57. add_header 'Access-Control-Allow-Credentials' 'true';
  58. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  59. if ($request_method = 'OPTIONS') {
  60. add_header 'Access-Control-Allow-Origin' "$http_origin";
  61. add_header 'Access-Control-Max-Age' 1728000;
  62. add_header 'Content-Type' 'text/plain charset=UTF-8';
  63. add_header 'Content-Length' 0;
  64. return 204;
  65. }
  66. types {
  67. application/dash+xml mpd;
  68. application/vnd.apple.mpegurl m3u8;
  69. video/mp2t ts;
  70. image/jpeg jpg;
  71. }
  72. root /tmp;
  73. }
  74. location /clips/ {
  75. add_header 'Access-Control-Allow-Origin' "$http_origin" always;
  76. add_header 'Access-Control-Allow-Credentials' 'true';
  77. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  78. if ($request_method = 'OPTIONS') {
  79. add_header 'Access-Control-Allow-Origin' "$http_origin";
  80. add_header 'Access-Control-Max-Age' 1728000;
  81. add_header 'Content-Type' 'text/plain charset=UTF-8';
  82. add_header 'Content-Length' 0;
  83. return 204;
  84. }
  85. types {
  86. video/mp4 mp4;
  87. image/jpeg jpg;
  88. }
  89. autoindex on;
  90. root /media/frigate;
  91. }
  92. location /recordings/ {
  93. add_header 'Access-Control-Allow-Origin' "$http_origin" always;
  94. add_header 'Access-Control-Allow-Credentials' 'true';
  95. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  96. if ($request_method = 'OPTIONS') {
  97. add_header 'Access-Control-Allow-Origin' "$http_origin";
  98. add_header 'Access-Control-Max-Age' 1728000;
  99. add_header 'Content-Type' 'text/plain charset=UTF-8';
  100. add_header 'Content-Length' 0;
  101. return 204;
  102. }
  103. types {
  104. video/mp4 mp4;
  105. }
  106. autoindex on;
  107. autoindex_format json;
  108. root /media/frigate;
  109. }
  110. location /ws {
  111. proxy_pass http://frigate_api/ws;
  112. proxy_http_version 1.1;
  113. proxy_set_header Upgrade $http_upgrade;
  114. proxy_set_header Connection "Upgrade";
  115. proxy_set_header Host $host;
  116. }
  117. location /api/ {
  118. add_header 'Access-Control-Allow-Origin' '*';
  119. add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
  120. add_header Cache-Control "no-store";
  121. proxy_pass http://frigate_api/;
  122. proxy_pass_request_headers on;
  123. proxy_set_header Host $host;
  124. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  125. proxy_set_header X-Forwarded-Proto $scheme;
  126. }
  127. location / {
  128. add_header Cache-Control "no-cache";
  129. location ~* \.(?:js|css|svg|ico|png)$ {
  130. access_log off;
  131. expires 1y;
  132. add_header Cache-Control "public";
  133. }
  134. sub_filter 'href="/' 'href="$http_x_ingress_path/';
  135. sub_filter 'url(/' 'url($http_x_ingress_path/';
  136. sub_filter '"/dist/' '"$http_x_ingress_path/dist/';
  137. sub_filter '"/js/' '"$http_x_ingress_path/js/';
  138. sub_filter '<body>' '<body><script>window.baseUrl="$http_x_ingress_path";</script>';
  139. sub_filter_types text/css application/javascript;
  140. sub_filter_once off;
  141. root /opt/frigate/web;
  142. try_files $uri $uri/ /index.html;
  143. }
  144. }
  145. }
  146. rtmp {
  147. server {
  148. listen 1935;
  149. chunk_size 4096;
  150. allow publish 127.0.0.1;
  151. deny publish all;
  152. allow play all;
  153. application live {
  154. live on;
  155. record off;
  156. meta copy;
  157. }
  158. }
  159. }