nginx.conf 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. secure_token $args;
  57. secure_token_types application/vnd.apple.mpegurl;
  58. add_header Access-Control-Allow-Headers '*';
  59. add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
  60. add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
  61. add_header Access-Control-Allow-Origin '*';
  62. expires -1;
  63. }
  64. location /stream/ {
  65. add_header 'Cache-Control' 'no-cache';
  66. add_header 'Access-Control-Allow-Origin' "$http_origin" always;
  67. add_header 'Access-Control-Allow-Credentials' 'true';
  68. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  69. if ($request_method = 'OPTIONS') {
  70. add_header 'Access-Control-Allow-Origin' "$http_origin";
  71. add_header 'Access-Control-Max-Age' 1728000;
  72. add_header 'Content-Type' 'text/plain charset=UTF-8';
  73. add_header 'Content-Length' 0;
  74. return 204;
  75. }
  76. types {
  77. application/dash+xml mpd;
  78. application/vnd.apple.mpegurl m3u8;
  79. video/mp2t ts;
  80. image/jpeg jpg;
  81. }
  82. root /tmp;
  83. }
  84. location /clips/ {
  85. add_header 'Access-Control-Allow-Origin' "$http_origin" always;
  86. add_header 'Access-Control-Allow-Credentials' 'true';
  87. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  88. if ($request_method = 'OPTIONS') {
  89. add_header 'Access-Control-Allow-Origin' "$http_origin";
  90. add_header 'Access-Control-Max-Age' 1728000;
  91. add_header 'Content-Type' 'text/plain charset=UTF-8';
  92. add_header 'Content-Length' 0;
  93. return 204;
  94. }
  95. types {
  96. video/mp4 mp4;
  97. image/jpeg jpg;
  98. }
  99. autoindex on;
  100. root /media/frigate;
  101. }
  102. location /recordings/ {
  103. add_header 'Access-Control-Allow-Origin' "$http_origin" always;
  104. add_header 'Access-Control-Allow-Credentials' 'true';
  105. add_header 'Access-Control-Expose-Headers' 'Content-Length';
  106. if ($request_method = 'OPTIONS') {
  107. add_header 'Access-Control-Allow-Origin' "$http_origin";
  108. add_header 'Access-Control-Max-Age' 1728000;
  109. add_header 'Content-Type' 'text/plain charset=UTF-8';
  110. add_header 'Content-Length' 0;
  111. return 204;
  112. }
  113. types {
  114. video/mp4 mp4;
  115. }
  116. autoindex on;
  117. autoindex_format json;
  118. root /media/frigate;
  119. }
  120. location /ws {
  121. proxy_pass http://mqtt_ws/;
  122. proxy_http_version 1.1;
  123. proxy_set_header Upgrade $http_upgrade;
  124. proxy_set_header Connection "Upgrade";
  125. proxy_set_header Host $host;
  126. }
  127. location /live/ {
  128. proxy_pass http://jsmpeg/;
  129. proxy_http_version 1.1;
  130. proxy_set_header Upgrade $http_upgrade;
  131. proxy_set_header Connection "Upgrade";
  132. proxy_set_header Host $host;
  133. }
  134. location /api/ {
  135. add_header 'Access-Control-Allow-Origin' '*';
  136. add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
  137. add_header Cache-Control "no-store";
  138. proxy_pass http://frigate_api/;
  139. proxy_pass_request_headers on;
  140. proxy_set_header Host $host;
  141. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  142. proxy_set_header X-Forwarded-Proto $scheme;
  143. }
  144. location / {
  145. add_header Cache-Control "no-cache";
  146. location ~* \.(?:js|css|svg|ico|png)$ {
  147. access_log off;
  148. expires 1y;
  149. add_header Cache-Control "public";
  150. }
  151. sub_filter 'href="/' 'href="$http_x_ingress_path/';
  152. sub_filter 'url(/' 'url($http_x_ingress_path/';
  153. sub_filter '"/dist/' '"$http_x_ingress_path/dist/';
  154. sub_filter '"/js/' '"$http_x_ingress_path/js/';
  155. sub_filter '<body>' '<body><script>window.baseUrl="$http_x_ingress_path";</script>';
  156. sub_filter_types text/css application/javascript;
  157. sub_filter_once off;
  158. root /opt/frigate/web;
  159. try_files $uri $uri/ /index.html;
  160. }
  161. }
  162. }
  163. rtmp {
  164. server {
  165. listen 1935;
  166. chunk_size 4096;
  167. allow publish 127.0.0.1;
  168. deny publish all;
  169. allow play all;
  170. application live {
  171. live on;
  172. record off;
  173. meta copy;
  174. }
  175. }
  176. }