Files
frigate/docker/main/rootfs/usr/local/nginx/conf/nginx.conf
T

357 lines
10 KiB
Nginx Configuration File
Raw Normal View History

2021-03-03 07:33:50 -06:00
daemon off;
2021-09-20 19:02:59 -05:00
user root;
2022-12-17 16:53:34 -07:00
worker_processes auto;
2020-11-02 05:44:16 -06:00
2022-12-17 16:53:34 -07:00
error_log /dev/stdout warn;
pid /var/run/nginx.pid;
2020-11-02 05:44:16 -06:00
events {
2022-12-17 16:53:34 -07:00
worker_connections 1024;
2020-11-02 05:44:16 -06:00
}
http {
2024-01-31 11:53:59 +00:00
map_hash_bucket_size 256;
2022-12-17 16:53:34 -07:00
include mime.types;
default_type application/octet-stream;
2020-11-02 05:44:16 -06:00
2022-12-17 16:53:34 -07:00
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
2020-11-02 05:44:16 -06:00
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'request_time="$request_time" upstream_response_time="$upstream_response_time"';
2020-11-02 05:44:16 -06:00
2022-12-17 16:53:34 -07:00
access_log /dev/stdout main;
2020-11-02 05:44:16 -06:00
2022-12-17 16:53:34 -07:00
# send headers in one piece, it is better than sending them one by one
tcp_nopush on;
2020-11-02 05:44:16 -06:00
2022-12-17 16:53:34 -07:00
sendfile on;
keepalive_timeout 65;
2020-11-02 05:44:16 -06:00
gzip on;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/x-javascript application/javascript text/javascript image/svg+xml image/x-icon image/bmp;
gzip_proxied no-cache no-store private expired auth;
gzip_vary on;
2023-10-29 07:47:24 -04:00
proxy_cache_path /dev/shm/nginx_cache levels=1:2 keys_zone=api_cache:10m max_size=10m inactive=1m use_temp_path=off;
2023-11-09 15:09:25 -07:00
map $sent_http_content_type $should_not_cache {
2023-11-07 16:18:58 -07:00
'application/json' 0;
default 1;
}
2020-11-08 16:35:21 -06:00
upstream frigate_api {
2022-12-17 16:53:34 -07:00
server 127.0.0.1:5001;
keepalive 1024;
2020-11-08 16:35:21 -06:00
}
2020-11-02 05:44:16 -06:00
2021-06-14 07:31:13 -05:00
upstream mqtt_ws {
2022-12-17 16:53:34 -07:00
server 127.0.0.1:5002;
keepalive 1024;
2021-06-14 07:31:13 -05:00
}
2021-03-02 06:54:12 -06:00
upstream jsmpeg {
2022-12-17 16:53:34 -07:00
server 127.0.0.1:8082;
keepalive 1024;
2021-03-02 06:54:12 -06:00
}
2024-06-01 10:29:46 -05:00
include go2rtc_upstream.conf;
server {
2024-06-02 07:48:28 -05:00
include listen.conf;
2024-06-01 10:29:46 -05:00
2026-03-11 08:32:16 -05:00
# enable HTTP/2 for TLS connections to eliminate browser 6-connection limit
http2 on;
2021-05-18 01:52:08 -04:00
# vod settings
vod_base_url '';
vod_segments_base_url '';
2021-05-18 01:52:08 -04:00
vod_mode mapped;
vod_max_mapping_response_size 1m;
vod_upstream_location /api;
vod_align_segments_to_key_frames on;
vod_manifest_segment_durations_mode accurate;
2022-08-26 19:33:16 +08:00
vod_ignore_edit_list on;
2022-12-17 16:53:34 -07:00
vod_segment_duration 10000;
2025-10-23 10:50:37 -06:00
# MPEG-TS settings (not used when fMP4 is enabled, kept for reference)
2022-12-17 16:53:34 -07:00
vod_hls_mpegts_align_frames off;
vod_hls_mpegts_interleave_frames on;
# file handle caching / aio
open_file_cache max=1000 inactive=5m;
open_file_cache_valid 2m;
open_file_cache_min_uses 1;
open_file_cache_errors on;
aio on;
2024-11-27 12:48:39 -07:00
# file upload size
2025-04-10 08:17:13 -05:00
client_max_body_size 20M;
2024-11-27 12:48:39 -07:00
2022-12-17 16:53:34 -07:00
# https://github.com/kaltura/nginx-vod-module#vod_open_file_thread_pool
vod_open_file_thread_pool default;
2021-05-18 01:52:08 -04:00
# vod caches
vod_metadata_cache metadata_cache 512m;
2021-12-12 08:03:38 -06:00
vod_mapping_cache mapping_cache 5m 10m;
2021-05-18 01:52:08 -04:00
# gzip manifests
gzip on;
gzip_types application/vnd.apple.mpegurl;
2024-05-18 11:36:13 -05:00
include auth_location.conf;
2025-03-17 16:29:38 +01:00
include base_path.conf;
2024-05-18 11:36:13 -05:00
2021-05-18 01:52:08 -04:00
location /vod/ {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
2022-12-17 16:53:34 -07:00
aio threads;
2021-05-18 01:52:08 -04:00
vod hls;
2025-10-23 10:50:37 -06:00
# Use fMP4 (fragmented MP4) instead of MPEG-TS for better performance
# Smaller segments, faster generation, better browser compatibility
2025-10-23 12:44:12 -06:00
vod_hls_container_format fmp4;
2025-10-23 10:50:37 -06:00
secure_token $args;
2022-12-17 16:53:34 -07:00
secure_token_types application/vnd.apple.mpegurl;
2022-04-25 08:00:01 -05:00
add_header Cache-Control "no-store";
expires off;
keepalive_disable safari;
# vod module returns 502 for non-existent media
# https://github.com/kaltura/nginx-vod-module/issues/468
error_page 502 =404 /vod-not-found;
}
location = /vod-not-found {
return 404;
2021-05-18 01:52:08 -04:00
}
2020-11-02 05:44:16 -06:00
location /stream/ {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
2022-04-25 08:00:01 -05:00
add_header Cache-Control "no-store";
expires off;
2020-11-02 05:44:16 -06:00
types {
application/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
image/jpeg jpg;
}
root /tmp;
}
2020-11-08 16:35:21 -06:00
location /clips/ {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
2020-11-02 05:44:16 -06:00
types {
video/mp4 mp4;
image/jpeg jpg;
}
expires 7d;
add_header Cache-Control "public";
2020-11-02 05:44:16 -06:00
autoindex on;
2020-11-08 16:35:21 -06:00
root /media/frigate;
}
2021-08-10 08:27:31 -05:00
location /cache/ {
2022-12-17 16:53:34 -07:00
internal; # This tells nginx it's not accessible from the outside
alias /tmp/cache/;
2021-08-10 08:27:31 -05:00
}
2020-11-30 07:56:19 -06:00
location /recordings/ {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
types {
video/mp4 mp4;
}
autoindex on;
autoindex_format json;
root /media/frigate;
}
location /exports/ {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
2020-11-30 07:56:19 -06:00
types {
video/mp4 mp4;
}
autoindex on;
autoindex_format json;
root /media/frigate;
}
2021-02-13 08:09:44 -06:00
location /ws {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
2021-06-14 07:31:13 -05:00
proxy_pass http://mqtt_ws/;
include proxy.conf;
2021-02-13 08:09:44 -06:00
}
location /live/jsmpeg/ {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
2021-03-02 06:54:12 -06:00
proxy_pass http://jsmpeg/;
include proxy.conf;
2021-03-02 06:54:12 -06:00
}
# frigate lovelace card uses this path
location /live/mse/api/ws {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
limit_except GET {
deny all;
}
proxy_pass http://go2rtc/api/ws;
include proxy.conf;
}
location /live/webrtc/api/ws {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
limit_except GET {
deny all;
}
proxy_pass http://go2rtc/api/ws;
include proxy.conf;
}
# pass through go2rtc player
location /live/webrtc/webrtc.html {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
limit_except GET {
deny all;
}
proxy_pass http://go2rtc/webrtc.html;
include proxy.conf;
}
# integration uses this to add webrtc candidate
location /api/go2rtc/webrtc {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
limit_except POST {
deny all;
}
proxy_pass http://go2rtc/api/webrtc;
include proxy.conf;
}
2024-03-12 17:19:16 -06:00
location ~* /api/.*\.(jpg|jpeg|png|webp|gif)$ {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
2024-09-24 14:05:30 +01:00
rewrite ^/api/(.*)$ /$1 break;
2022-08-25 20:32:30 +08:00
proxy_pass http://frigate_api;
include proxy.conf;
2022-04-25 08:00:01 -05:00
}
2021-01-09 09:26:46 -08:00
location /api/ {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
2022-04-25 08:00:01 -05:00
add_header Cache-Control "no-store";
expires off;
2020-11-08 16:35:21 -06:00
proxy_pass http://frigate_api/;
include proxy.conf;
2023-10-29 07:47:24 -04:00
proxy_cache api_cache;
2026-05-20 09:36:49 -05:00
proxy_cache_key "$scheme$proxy_host$request_uri|$role|$groups|$user";
2023-10-29 07:47:24 -04:00
proxy_cache_lock on;
proxy_cache_use_stale updating;
proxy_cache_valid 200 5s;
proxy_cache_bypass $http_x_cache_bypass;
2023-11-07 16:18:58 -07:00
proxy_no_cache $should_not_cache;
2023-10-29 07:47:24 -04:00
add_header X-Cache-Status $upstream_cache_status;
location /api/vod/ {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
2023-10-29 07:47:24 -04:00
proxy_pass http://frigate_api/vod/;
include proxy.conf;
proxy_cache off;
}
2024-05-18 11:36:13 -05:00
location /api/login {
auth_request off;
rewrite ^/api(/.*)$ $1 break;
proxy_pass http://frigate_api;
include proxy.conf;
}
2025-10-22 12:24:53 -05:00
# Allow unauthenticated access to the first_time_login endpoint
# so the login page can load help text before authentication.
location /api/auth/first_time_login {
auth_request off;
limit_except GET {
deny all;
}
rewrite ^/api(/.*)$ $1 break;
proxy_pass http://frigate_api;
include proxy.conf;
}
location /api/stats {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
access_log off;
rewrite ^/api(/.*)$ $1 break;
2023-10-21 11:40:46 -04:00
proxy_pass http://frigate_api;
include proxy.conf;
}
location /api/version {
2024-05-18 11:36:13 -05:00
include auth_request.conf;
access_log off;
rewrite ^/api(/.*)$ $1 break;
2023-10-21 11:40:46 -04:00
proxy_pass http://frigate_api;
include proxy.conf;
}
2020-11-02 05:44:16 -06:00
}
2021-01-09 09:26:46 -08:00
location / {
2024-05-18 11:36:13 -05:00
# do not require auth for static assets
2022-04-25 08:00:01 -05:00
add_header Cache-Control "no-store";
expires off;
2022-04-25 08:00:01 -05:00
location /assets/ {
access_log off;
expires 1y;
add_header Cache-Control "public";
}
2025-11-20 16:50:17 -07:00
location /fonts/ {
access_log off;
expires 1y;
add_header Cache-Control "public";
}
2025-03-19 07:50:36 -05:00
location /locales/ {
access_log off;
add_header Cache-Control "public";
}
2025-03-17 16:29:38 +01:00
location ~ ^/.*-([A-Za-z0-9]+)\.webmanifest$ {
access_log off;
expires 1y;
add_header Cache-Control "public";
default_type application/json;
proxy_set_header Accept-Encoding "";
sub_filter_once off;
sub_filter_types application/json;
sub_filter '"start_url": "/BASE_PATH/"' '"start_url" : "$http_x_ingress_path/"';
sub_filter '"src": "/BASE_PATH/' '"src": "$http_x_ingress_path/';
2025-03-17 16:29:38 +01:00
}
2022-05-19 07:31:02 -05:00
sub_filter 'href="/BASE_PATH/' 'href="$http_x_ingress_path/';
sub_filter 'url(/BASE_PATH/' 'url($http_x_ingress_path/';
sub_filter '"/BASE_PATH/dist/' '"$http_x_ingress_path/dist/';
sub_filter '"/BASE_PATH/js/' '"$http_x_ingress_path/js/';
sub_filter '"/BASE_PATH/assets/' '"$http_x_ingress_path/assets/';
2025-03-18 09:08:44 -05:00
sub_filter '"/BASE_PATH/locales/' '"$http_x_ingress_path/locales/';
2022-12-17 16:55:41 -07:00
sub_filter '"/BASE_PATH/monacoeditorwork/' '"$http_x_ingress_path/assets/';
2022-11-17 07:05:27 -06:00
sub_filter 'return"/BASE_PATH/"' 'return window.baseUrl';
2022-05-19 07:31:02 -05:00
sub_filter '<body>' '<body><script>window.baseUrl="$http_x_ingress_path/";</script>';
2021-01-19 19:58:17 -06:00
sub_filter_types text/css application/javascript;
sub_filter_once off;
2021-01-19 19:58:17 -06:00
root /opt/frigate/web;
2024-05-18 11:36:13 -05:00
try_files $uri $uri.html $uri/ /index.html;
2021-01-09 09:26:46 -08:00
}
2020-11-02 05:44:16 -06:00
}
2020-11-28 07:58:27 -06:00
}