Files
hassio-addons/birdnet-pipy/rootfs/etc/cont-init.d/32-nginx_ingress.sh
Yudong Sun 809d5271ef fix(birdnet-pipy): build ingress.conf from the server block only
Upstream 0.8.2 added http-level limit_req_zone directives to its
nginx.conf. The ingress config was a wholesale copy of that file, and
both land in the same http context via servers/*.conf — nginx refuses
to declare a named shared-memory zone twice and dies at startup with
'limit_req_zone "api_rl" already bound' (502 on every page). Extract
everything from the column-0 "server {" onward instead, so maps and
zones stay declared once; zone/variable references resolve across
included files regardless of include order. Also comment out the new
Content-Security-Policy header in the ingress copy, matching the
existing X-* handling.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016acGazhHvyCNUFt71xzFxm
2026-07-04 09:37:02 -04:00

42 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
set -e
#################
# NGINX SETTING #
#################
declare ingress_interface
declare ingress_port
ingress_port="$(bashio::addon.ingress_port)"
ingress_interface="$(bashio::addon.ip_address)"
ingress_entry="$(bashio::addon.ingress_entry)"
sed -i \
-e "s|proxy_pass http://api|proxy_pass http://127.0.0.1|g" \
-e "s|proxy_pass http://icecast|proxy_pass http://127.0.0.1|g" \
/etc/nginx/servers/nginx.conf
if ! [[ "${ingress_port}" =~ ^[0-9]+$ ]] || [[ "${ingress_port}" -le 0 ]]; then
bashio::log.info "Ingress not active, disabling nginx service"
touch /run/nginx-disabled
exit 0
fi
# Build the ingress server from the server block ONLY. Both files in
# servers/ are included into one http context, so http-level directives
# (map, limit_req_zone, ...) must stay declared once, in nginx.conf — a
# duplicated limit_req_zone is a fatal "already bound" error and nginx
# never starts (502 on every page). Upstream keeps all http-level
# directives above its single column-0 "server {".
sed -n '/^server {/,$p' /etc/nginx/servers/nginx.conf > /etc/nginx/servers/ingress.conf
sed -i \
-e "s|listen 80;|listen ${ingress_interface}:${ingress_port} default_server;|g" \
-e "/index index.html;/a\\ include /etc/nginx/includes/ingress_params.conf;" \
-e 's|^[[:space:]]*add_header X|#&|g' \
-e 's|^[[:space:]]*add_header Content-Security-Policy|#&|g' \
/etc/nginx/servers/ingress.conf
sed -i "s#%%ingress_entry%%#${ingress_entry}#g" /etc/nginx/includes/ingress_params.conf