nginx.conf 6.0 KB

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