Nginx listen and cache header fixes (#25092)

* only add the ipv6 listener for wildcard listen addresses

With IPv6 enabled, nginx also listened on [::] for both ports regardless of the configured listen address, so an internal port bound to 127.0.0.1 or [::1] was still reachable on every IPv6 address, and a [::]:port value rendered a duplicate listen that kept nginx from starting. The [::] listener is now added only for a bare port, *:port or 0.0.0.0:port, and a specific address binds only that address.

* mark authorized media responses private in nginx
This commit is contained in:
Josh Hawkins
2026-11-25 07:40:26 -07:00
committed by GitHub
parent fd35f4a48f
commit b213d1e73c
6 changed files with 45 additions and 9 deletions
@@ -183,7 +183,7 @@ http {
}
expires 7d;
add_header Cache-Control "public";
add_header Cache-Control "private";
autoindex on;
root /media/frigate;
@@ -205,6 +205,7 @@ http {
video/mp4 mp4;
}
add_header Cache-Control "private";
autoindex on;
autoindex_format json;
root /media/frigate;
@@ -216,6 +217,7 @@ http {
video/mp4 mp4;
}
add_header Cache-Control "private";
autoindex on;
autoindex_format json;
root /media/frigate;
@@ -8,7 +8,11 @@ from typing import Any
from ruamel.yaml import YAML
sys.path.insert(0, "/opt/frigate")
from frigate.util.config import find_config_file, parse_listen_address
from frigate.util.config import (
find_config_file,
ipv6_listen_address,
parse_listen_address,
)
sys.path.remove("/opt/frigate")
@@ -51,6 +55,9 @@ for key, default in (("internal", 5000), ("external", 8971)):
listen_config[key] = value
listen_config[f"{key}_port"] = port
listen_config[f"{key}_ipv6"] = (
ipv6_listen_address(value, port) if ipv6_config["enabled"] else None
)
if listen_config["internal_port"] == listen_config["external_port"]:
print(
@@ -1,12 +1,12 @@
# Internal (IPv4 always; IPv6 optional)
# Internal; a wildcard address also listens on [::] when IPv6 is enabled
listen {{ .listen.internal }};
{{ if .ipv6.enabled }}listen [::]:{{ .listen.internal_port }};{{ end }}
{{ if .listen.internal_ipv6 }}listen {{ .listen.internal_ipv6 }};{{ end }}
# intended for external traffic, protected by auth
{{ if .tls.enabled }}
# external HTTPS (IPv4 always; IPv6 optional)
# external HTTPS
listen {{ .listen.external }} ssl;
{{ if .ipv6.enabled }}listen [::]:{{ .listen.external_port }} ssl;{{ end }}
{{ if .listen.external_ipv6 }}listen {{ .listen.external_ipv6 }} ssl;{{ end }}
ssl_certificate {{ .tls.cert_path }}/fullchain.pem;
ssl_certificate_key {{ .tls.cert_path }}/privkey.pem;
@@ -30,7 +30,7 @@ listen {{ .listen.internal }};
root /etc/letsencrypt/www;
}
{{ else }}
# (No tls) default to HTTP (IPv4 always; IPv6 optional)
# (No tls) default to HTTP
listen {{ .listen.external }};
{{ if .ipv6.enabled }}listen [::]:{{ .listen.external_port }};{{ end }}
{{ if .listen.external_ipv6 }}listen {{ .listen.external_ipv6 }};{{ end }}
{{ end }}
+1 -1
View File
@@ -287,7 +287,7 @@ Frigate exposes a few networking options. IPv6 and the listen ports are set in t
### Enabling IPv6
By default Frigate listens on IPv4 only. To also listen on IPv6 (on port `5000`, and on `8971` when TLS is configured), enable it in the `networking` configuration.
By default Frigate listens on IPv4 only. To also listen on IPv6 (on port `5000`, and on `8971` when TLS is configured), enable it in the `networking` configuration. A listen port bound to a specific address stays on that address only.
<ConfigTabs>
<TabItem value="ui">
+15
View File
@@ -5,6 +5,7 @@ import unittest
from pydantic import ValidationError
from frigate.config.network import ListenConfig
from frigate.util.config import ipv6_listen_address, parse_listen_address
class TestListenConfig(unittest.TestCase):
@@ -104,5 +105,19 @@ class TestListenConfig(unittest.TestCase):
ListenConfig(internal=value)
class TestIPv6ListenAddress(unittest.TestCase):
def test_wildcard_adds_ipv6_wildcard(self):
for raw in (5000, "*:5000", "0.0.0.0:5000"):
with self.subTest(raw=raw):
value, port = parse_listen_address(raw)
self.assertEqual(ipv6_listen_address(value, port), "[::]:5000")
def test_specific_address_adds_nothing(self):
for raw in ("127.0.0.1:5000", "localhost:5000", "[::1]:5000", "[::]:5000"):
with self.subTest(raw=raw):
value, port = parse_listen_address(raw)
self.assertIsNone(ipv6_listen_address(value, port))
if __name__ == "__main__":
unittest.main(verbosity=2)
+12
View File
@@ -195,6 +195,18 @@ def parse_listen_address(value: int | str) -> tuple[int | str, int]:
return f"{host}:{port}", port
def ipv6_listen_address(value: int | str, port: int) -> str | None:
"""Return the IPv6 wildcard address to add for a parsed listen value.
Only an IPv4 wildcard gains the extra IPv6 listener. A specific address
binds only that address, and nginx would let a [::] listener override it.
"""
if isinstance(value, int) or value.startswith(("*:", "0.0.0.0:")):
return f"[::]:{port}"
return None
def find_config_file() -> str:
"""Return the path of the config file to use.