nginx.conf 5.9 KB

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