nginx.conf 6.4 KB

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