nginx.conf 6.7 KB

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