mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-06-21 23:09:14 +02:00
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:
@@ -4,16 +4,15 @@ server {
|
|||||||
include /etc/nginx/includes/proxy_params.conf;
|
include /etc/nginx/includes/proxy_params.conf;
|
||||||
|
|
||||||
location / {
|
location / {
|
||||||
|
proxy_pass http://localhost:8080/;
|
||||||
|
rewrite ^%%ingress_entry%%/(.*)$ /$1 break;
|
||||||
|
|
||||||
# Proxy pass
|
# Disable buffering (required for SSE and sub_filter)
|
||||||
proxy_pass http://localhost:8080;
|
|
||||||
|
|
||||||
# Disable buffering
|
|
||||||
proxy_buffering off;
|
proxy_buffering off;
|
||||||
proxy_request_buffering off;
|
proxy_request_buffering off;
|
||||||
proxy_cache off;
|
proxy_cache off;
|
||||||
|
|
||||||
# Next three lines allow websockets
|
# WebSocket support
|
||||||
proxy_http_version 1.1;
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
proxy_set_header Connection $connection_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-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
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
|
# Prevent timeouts
|
||||||
proxy_read_timeout 86400;
|
proxy_read_timeout 86400;
|
||||||
proxy_send_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
|
# sub_filter setup
|
||||||
set $today "";
|
proxy_set_header Accept-Encoding "";
|
||||||
if ($time_iso8601 ~ "^(\d{4}-\d{2}-\d{2})") {
|
sub_filter_once off;
|
||||||
set $today $1;
|
sub_filter_types *;
|
||||||
}
|
|
||||||
sub_filter 'id="datePicker"' 'id="datePicker" value="$today"';
|
|
||||||
|
|
||||||
}
|
# 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%%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user