nginx.conf 6.2 KB

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