Base path via environment variable (#17030)

* Base path via environment variable

* Feedback refactored

* Update docker/main/rootfs/usr/local/nginx/conf/nginx.conf

Co-authored-by: Blake Blackshear <blake.blackshear@gmail.com>

* Update docker/main/rootfs/usr/local/nginx/templates/base_path.gotmpl

Co-authored-by: Blake Blackshear <blake.blackshear@gmail.com>

* Revert api regex change

* Lint fix

* Fix https to http

* Base path documentation

* Base path contains leading slash

* Frigate specific environment variable

* Typo in comment

Co-authored-by: Blake Blackshear <blake.blackshear@gmail.com>

* Typo in comment

Co-authored-by: Blake Blackshear <blake.blackshear@gmail.com>

---------

Co-authored-by: Blake Blackshear <blake.blackshear@gmail.com>
This commit is contained in:
bartbutenaers
2025-03-17 16:29:38 +01:00
committed by GitHub
parent 95e141ed15
commit 61aef0bff0
5 changed files with 79 additions and 0 deletions

View File

@@ -96,6 +96,7 @@ http {
gzip_types application/vnd.apple.mpegurl;
include auth_location.conf;
include base_path.conf;
location /vod/ {
include auth_request.conf;
@@ -299,6 +300,18 @@ http {
add_header Cache-Control "public";
}
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": "/"' '"start_url" : "$http_x_ingress_path"';
sub_filter '"src": "/' '"src": "$http_x_ingress_path/';
}
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/';

View File

@@ -0,0 +1,10 @@
"""Prints the base path as json to stdout."""
import json
import os
base_path = os.environ.get("FRIGATE_BASE_PATH", "")
result: dict[str, any] = {"base_path": base_path}
print(json.dumps(result))

View File

@@ -0,0 +1,19 @@
{{ if .base_path }}
location = {{ .base_path }} {
return 302 {{ .base_path }}/;
}
location ^~ {{ .base_path }}/ {
# remove base_url from the path before passing upstream
rewrite ^{{ .base_path }}/(.*) /$1 break;
proxy_pass $scheme://127.0.0.1:8971;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Ingress-Path {{ .base_path }};
access_log off;
}
{{ end }}