Enhance Nginx ingress configuration with rewrites

Updated Nginx configuration to support ingress entry rewrites and added sub_filter directives for various paths.
This commit is contained in:
Alexandre
2026-02-17 17:01:57 +01:00
committed by GitHub
parent 327385053b
commit 50e79862d0

View File

@@ -4,16 +4,15 @@ server {
include /etc/nginx/includes/proxy_params.conf;
location / {
proxy_pass http://localhost:8080/;
rewrite ^%%ingress_entry%%/(.*)$ /$1 break;
# Proxy pass
proxy_pass http://localhost:8080;
# Disable buffering
# Disable buffering (required for SSE and sub_filter)
proxy_buffering off;
proxy_request_buffering off;
proxy_cache off;
# Next three lines allow websockets
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
@@ -22,20 +21,40 @@ server {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Tell BirdNET-Go its proxy prefix (NEW — required)
proxy_set_header X-Ingress-Path %%ingress_entry%%;
# Prevent timeouts
proxy_read_timeout 86400;
proxy_send_timeout 86400;
# SSE-specific headers
add_header Cache-Control no-cache;
add_header Content-Type text/event-stream;
# Define date for frontpage
set $today "";
if ($time_iso8601 ~ "^(\d{4}-\d{2}-\d{2})") {
set $today $1;
}
sub_filter 'id="datePicker"' 'id="datePicker" value="$today"';
# sub_filter setup
proxy_set_header Accept-Encoding "";
sub_filter_once off;
sub_filter_types *;
}
# HTML attribute rewrites
sub_filter href=\"/ href=\"%%ingress_entry%%/;
sub_filter src=\"/ src=\"%%ingress_entry%%/;
sub_filter src=\"'/ src=\"'%%ingress_entry%%/;
sub_filter action=\"/ action=\"%%ingress_entry%%/;
# JavaScript string rewrites (needed for Vite dynamic imports)
sub_filter EventSource('/ EventSource('%%ingress_entry%%/;
sub_filter fetch('/ fetch('%%ingress_entry%%/;
# Backtick template literal rewrites
sub_filter `/api/v `%%ingress_entry%%/api/v;
sub_filter "'/api/v" "'%%ingress_entry%%/api/v";
sub_filter \"/api/v \"%%ingress_entry%%/api/v;
sub_filter `/u `%%ingress_entry%%/u;
sub_filter "'/u" "'%%ingress_entry%%/u";
sub_filter \"/u \"%%ingress_entry%%/u;
sub_filter `/asset `%%ingress_entry%%/asset;
sub_filter "'/asset" "'%%ingress_entry%%/asset";
sub_filter \"/asset \"%%ingress_entry%%/asset;
# Streaming/EventSource fix
sub_filter window.location.origin} window.location.origin}%%ingress_entry%%;
}
}