2021-03-03 16:33:50 +03:00
daemon off ;
2021-09-21 03:02:59 +03:00
user root ;
2022-12-18 02:53:34 +03:00
worker_processes auto ;
2020-11-02 14:44:16 +03:00
2022-12-18 02:53:34 +03:00
error_log /dev/stdout warn ;
pid /var/run/nginx.pid ;
2020-11-02 14:44:16 +03:00
events {
2022-12-18 02:53:34 +03:00
worker_connections 1024 ;
2020-11-02 14:44:16 +03:00
}
http {
2024-01-31 14:53:59 +03:00
map_hash_bucket_size 256 ;
2022-12-18 02:53:34 +03:00
include mime.types ;
default_type application/octet-stream ;
2020-11-02 14:44:16 +03:00
2022-12-18 02:53:34 +03:00
log_format main ' $remote_addr - $remote_user [ $time_local] " $request" '
2020-11-02 14:44:16 +03:00
'$status $body_bytes_sent " $http_referer" '
'"$http_user_agent" " $http_x_forwarded_for"' ;
2022-12-18 02:53:34 +03:00
access_log /dev/stdout main ;
2020-11-02 14:44:16 +03:00
2022-12-18 02:53:34 +03:00
# send headers in one piece, it is better than sending them one by one
tcp_nopush on ;
2020-11-02 14:44:16 +03:00
2022-12-18 02:53:34 +03:00
sendfile on ;
keepalive_timeout 65 ;
2020-11-02 14:44:16 +03:00
2021-01-29 08:04:52 +03: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 image/png image/gif image/jpeg image/jpg ;
gzip_proxied no-cache no-store private expired auth ;
gzip_vary on ;
2023-10-29 14:47:24 +03: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-10 01:09:25 +03:00
map $sent_http_content_type $should_not_cache {
2023-11-08 02:18:58 +03:00
'application/json' 0 ;
default 1 ;
}
2020-11-09 01:35:21 +03:00
upstream frigate_api {
2022-12-18 02:53:34 +03:00
server 127.0.0.1 : 5001 ;
keepalive 1024 ;
2020-11-09 01:35:21 +03:00
}
2020-11-02 14:44:16 +03:00
2021-06-14 15:31:13 +03:00
upstream mqtt_ws {
2022-12-18 02:53:34 +03:00
server 127.0.0.1 : 5002 ;
keepalive 1024 ;
2021-06-14 15:31:13 +03:00
}
2021-03-02 15:54:12 +03:00
upstream jsmpeg {
2022-12-18 02:53:34 +03:00
server 127.0.0.1 : 8082 ;
keepalive 1024 ;
2021-03-02 15:54:12 +03:00
}
2024-06-01 18:29:46 +03:00
include go2rtc_upstream.conf ;
server {
2024-06-02 15:48:28 +03:00
include listen.conf ;
2024-06-01 18:29:46 +03:00
2021-05-18 08:52:08 +03:00
# vod settings
2021-06-03 19:17:08 +03:00
vod_base_url '' ;
vod_segments_base_url '' ;
2021-05-18 08:52:08 +03:00
vod_mode mapped ;
vod_max_mapping_response_size 1m ;
vod_upstream_location /api ;
2021-08-29 05:26:23 +03:00
vod_align_segments_to_key_frames on ;
vod_manifest_segment_durations_mode accurate ;
2022-08-26 14:33:16 +03:00
vod_ignore_edit_list on ;
2022-12-18 02:53:34 +03:00
vod_segment_duration 10000 ;
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 ;
# https://github.com/kaltura/nginx-vod-module#vod_open_file_thread_pool
vod_open_file_thread_pool default ;
2021-05-18 08:52:08 +03:00
# vod caches
vod_metadata_cache metadata_cache 512m ;
2021-12-12 17:03:38 +03:00
vod_mapping_cache mapping_cache 5m 10m ;
2021-05-18 08:52:08 +03:00
# gzip manifests
gzip on ;
gzip_types application/vnd .apple.mpegurl ;
2024-05-18 19:36:13 +03:00
include auth_location.conf ;
2021-05-18 08:52:08 +03:00
location /vod/ {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2022-12-18 02:53:34 +03:00
aio threads ;
2021-05-18 08:52:08 +03:00
vod hls ;
2021-07-13 04:54:12 +03:00
secure_token $args ;
2022-12-18 02:53:34 +03:00
secure_token_types application/vnd .apple.mpegurl ;
2021-07-13 04:54:12 +03:00
2022-04-25 16:00:01 +03:00
add_header Cache-Control "no-store" ;
expires off ;
2021-05-18 08:52:08 +03:00
}
2020-11-02 14:44:16 +03:00
location /stream/ {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2022-04-25 16:00:01 +03:00
add_header Cache-Control "no-store" ;
expires off ;
2020-11-02 14:44:16 +03:00
types {
application/dash+xml mpd ;
application/vnd.apple.mpegurl m3u8 ;
video/mp2t ts ;
image/jpeg jpg ;
}
root /tmp ;
}
2020-11-09 01:35:21 +03:00
location /clips/ {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2020-11-02 14:44:16 +03:00
types {
video/mp4 mp4 ;
image/jpeg jpg ;
}
2024-06-09 21:45:26 +03:00
expires 7d ;
add_header Cache-Control "public" ;
2020-11-02 14:44:16 +03:00
autoindex on ;
2020-11-09 01:35:21 +03:00
root /media/frigate ;
}
2021-08-10 16:27:31 +03:00
location /cache/ {
2022-12-18 02:53:34 +03:00
internal ; # This tells nginx it's not accessible from the outside
alias /tmp/cache/ ;
2021-08-10 16:27:31 +03:00
}
2020-11-30 16:56:19 +03:00
location /recordings/ {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2023-06-08 14:32:35 +03:00
types {
video/mp4 mp4 ;
}
autoindex on ;
autoindex_format json ;
root /media/frigate ;
}
location /exports/ {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2020-11-30 16:56:19 +03:00
types {
video/mp4 mp4 ;
}
autoindex on ;
autoindex_format json ;
root /media/frigate ;
}
2021-02-13 17:09:44 +03:00
location /ws {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2021-06-14 15:31:13 +03:00
proxy_pass http://mqtt_ws/ ;
2023-10-21 16:15:24 +03:00
include proxy.conf ;
2021-02-13 17:09:44 +03:00
}
2022-11-02 14:36:09 +03:00
location /live/jsmpeg/ {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2021-03-02 15:54:12 +03:00
proxy_pass http://jsmpeg/ ;
2023-10-21 16:15:24 +03:00
include proxy.conf ;
2021-03-02 15:54:12 +03:00
}
2023-11-28 03:25:47 +03:00
# frigate lovelace card uses this path
location /live/mse/api/ws {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2023-11-28 03:25:47 +03:00
limit_except GET {
deny all ;
}
proxy_pass http://go2rtc/api/ws ;
2023-10-21 16:15:24 +03:00
include proxy.conf ;
2022-11-02 14:36:09 +03:00
}
2023-11-28 03:25:47 +03:00
location /live/webrtc/api/ws {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2023-11-28 03:25:47 +03:00
limit_except GET {
deny all ;
}
proxy_pass http://go2rtc/api/ws ;
2023-10-21 16:15:24 +03:00
include proxy.conf ;
2022-11-02 14:36:09 +03:00
}
2023-11-28 03:25:47 +03:00
# pass through go2rtc player
location /live/webrtc/webrtc.html {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2023-11-28 03:25:47 +03:00
limit_except GET {
deny all ;
}
proxy_pass http://go2rtc/webrtc.html ;
include proxy.conf ;
}
# frontend uses this to fetch the version
location /api/go2rtc/api {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2023-11-28 03:25:47 +03:00
limit_except GET {
deny all ;
}
proxy_pass http://go2rtc/api ;
2023-10-21 16:15:24 +03:00
include proxy.conf ;
2023-05-05 05:04:06 +03:00
}
2023-12-01 16:47:09 +03:00
# integration uses this to add webrtc candidate
location /api/go2rtc/webrtc {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2023-12-01 16:47:09 +03:00
limit_except POST {
deny all ;
}
proxy_pass http://go2rtc/api/webrtc ;
include proxy.conf ;
}
2024-08-24 19:49:02 +03:00
# FIXME: Needed to disabled this rule, otherwise it fails for endpoints that end with one of those file extensions
# 1. with httptools it passes the auth.conf but then throws a 400 error "WARN "Invalid HTTP request received." -> https://github.com/encode/uvicorn/blob/47304d9ae76321f0f5f649ff4f73e09b17085933/uvicorn/protocols/http/httptools_impl.py#L165
# 2. With h11 it goes through the auth.conf but returns a 404 error
# We might need to add extra rules that will allow endpoint that end with an extension OR find a fix without creating other rules
# location ~* /api/.*\.(jpg|jpeg|png|webp|gif)$ {
# include auth_request.conf;
# rewrite ^/api/(.*)$ $1 break;
# proxy_pass http://frigate_api;
# include proxy.conf;
# }
2022-04-25 16:00:01 +03:00
2021-01-09 20:26:46 +03:00
location /api/ {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2022-04-25 16:00:01 +03:00
add_header Cache-Control "no-store" ;
expires off ;
2020-11-09 01:35:21 +03:00
proxy_pass http://frigate_api/ ;
2023-10-21 16:15:24 +03:00
include proxy.conf ;
2023-10-29 14:47:24 +03:00
proxy_cache api_cache ;
proxy_cache_lock on ;
proxy_cache_use_stale updating ;
proxy_cache_valid 200 5s ;
proxy_cache_bypass $http_x_cache_bypass ;
2023-11-08 02:18:58 +03:00
proxy_no_cache $should_not_cache ;
2023-10-29 14:47:24 +03:00
add_header X-Cache-Status $upstream_cache_status ;
location /api/vod/ {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2023-10-29 14:47:24 +03:00
proxy_pass http://frigate_api/vod/ ;
include proxy.conf ;
proxy_cache off ;
}
2024-05-18 19:36:13 +03:00
location /api/login {
auth_request off ;
rewrite ^/api(/.*) $ $1 break ;
proxy_pass http://frigate_api ;
include proxy.conf ;
}
2023-10-21 16:15:24 +03:00
location /api/stats {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2023-10-21 16:15:24 +03:00
access_log off ;
2024-04-11 14:41:07 +03:00
rewrite ^/api(/.*) $ $1 break ;
2023-10-21 18:40:46 +03:00
proxy_pass http://frigate_api ;
2023-10-21 16:15:24 +03:00
include proxy.conf ;
}
location /api/version {
2024-05-18 19:36:13 +03:00
include auth_request.conf ;
2023-10-21 16:15:24 +03:00
access_log off ;
2024-04-11 14:41:07 +03:00
rewrite ^/api(/.*) $ $1 break ;
2023-10-21 18:40:46 +03:00
proxy_pass http://frigate_api ;
2023-10-21 16:15:24 +03:00
include proxy.conf ;
}
2020-11-02 14:44:16 +03:00
}
2021-01-09 20:26:46 +03:00
location / {
2024-05-18 19:36:13 +03:00
# do not require auth for static assets
2022-04-25 16:00:01 +03:00
add_header Cache-Control "no-store" ;
expires off ;
2021-01-29 08:04:52 +03:00
2022-04-25 16:00:01 +03:00
location /assets/ {
2021-01-29 08:04:52 +03:00
access_log off ;
expires 1y ;
add_header Cache-Control "public" ;
}
2022-05-19 15:31:02 +03: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/' ;
2022-12-18 02:55:41 +03:00
sub_filter '"/BASE_PATH/monacoeditorwork/' '" $http_x_ingress_path/assets/' ;
2022-11-17 16:05:27 +03:00
sub_filter 'return"/BASE_PATH/"' 'return window.baseUrl' ;
2022-05-19 15:31:02 +03:00
sub_filter '<body>' '<body><script>window.baseUrl=" $http_x_ingress_path/" ; </script>' ;
2021-01-20 04:58:17 +03:00
sub_filter_types text/css application/javascript ;
sub_filter_once off ;
2021-01-29 08:04:52 +03:00
2021-01-20 04:58:17 +03:00
root /opt/frigate/web ;
2024-05-18 19:36:13 +03:00
try_files $uri $uri.html $uri/ /index.html ;
2021-01-09 20:26:46 +03:00
}
2020-11-02 14:44:16 +03:00
}
2020-11-28 16:58:27 +03:00
}