nginx.conf 6.7 KB

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