Updated NGINX configuration handling for ingress setup.
This commit is contained in:
Alexandre
2025-11-16 20:37:32 +01:00
committed by GitHub
parent 613c1767d5
commit 1da36b5f7a

View File

@@ -2,39 +2,34 @@
# shellcheck shell=bash # shellcheck shell=bash
set -e set -e
# nginx Path
NGINX_CONFIG=/etc/nginx/sites-available/ingress.conf NGINX_CONFIG=/etc/nginx/sites-available/ingress.conf
SUBFOLDER="$(bashio::addon.ingress_entry)" SUBFOLDER="$(bashio::addon.ingress_entry)"
# Ensure subfolder ends with a trailing slash (except for root) # Copy template
if [[ -n "${SUBFOLDER}" && "${SUBFOLDER}" != "/" ]]; then
[[ "${SUBFOLDER}" == */ ]] || SUBFOLDER="${SUBFOLDER}/"
else
SUBFOLDER="/"
fi
cp /defaults/default.conf "${NGINX_CONFIG}" cp /defaults/default.conf "${NGINX_CONFIG}"
# Keep only the first (non-SSL) server block # Keep only the first (non-SSL) server block
awk -v n=2 '/^[[:space:]]*server[[:space:]]*\{/{n--} n>0' "${NGINX_CONFIG}" > tmpfile awk -v n=2 '/^[[:space:]]*server[[:space:]]*\{/{n--} n>0' "${NGINX_CONFIG}" > tmpfile
mv tmpfile "${NGINX_CONFIG}" mv tmpfile "${NGINX_CONFIG}"
# Disable IPv6 listeners for ingress proxying # Remove ipv6
sed -i '/listen \[::\]/d' "${NGINX_CONFIG}" sed -i '/listen \[::\]/d' "${NGINX_CONFIG}"
# Adapt ports and upstream paths for Home Assistant ingress # Add ingress parameters
sed -i "s|3000|$(bashio::addon.ingress_port)|g" "${NGINX_CONFIG}" sed -i "s|3000|$(bashio::addon.ingress_port)|g" "${NGINX_CONFIG}"
sed -i "s|SUBFOLDER|${SUBFOLDER}|g" "${NGINX_CONFIG}"
sed -i "s|CWS|8082|g" "${NGINX_CONFIG}"
sed -i "s|REPLACE_HOME|${HOME:-/root}|g" "${NGINX_CONFIG}"
sed -i "s|REPLACE_DOWNLOADS_PATH|${HOME:-/config}|g" "${NGINX_CONFIG}"
sed -i '/proxy_buffering/a proxy_set_header Accept-Encoding "";' "${NGINX_CONFIG}" sed -i '/proxy_buffering/a proxy_set_header Accept-Encoding "";' "${NGINX_CONFIG}"
sed -i '/proxy_buffering/a sub_filter_once off;' "${NGINX_CONFIG}" sed -i '/proxy_buffering/a sub_filter_once off;' "${NGINX_CONFIG}"
sed -i '/proxy_buffering/a sub_filter_types *;' "${NGINX_CONFIG}" sed -i '/proxy_buffering/a sub_filter_types *;' "${NGINX_CONFIG}"
sed -i '/proxy_buffering/a sub_filter "vnc/index.html?autoconnect" "vnc/index.html?path=%%path%%/websockify?autoconnect";' "${NGINX_CONFIG}" sed -i '/proxy_buffering/a sub_filter "vnc/index.html?autoconnect" "vnc/index.html?path=%%path%%/websockify?autoconnect";' "${NGINX_CONFIG}"
sed -i "s|%%path%%|${SUBFOLDER:1}|g" "${NGINX_CONFIG}" sed -i "s|%%path%%|${SUBFOLDER:1}|g" "${NGINX_CONFIG}"
# Avoid content encoding on proxied responses to keep Selkies happy # Replace placeholders
sed -i '/proxy_buffering/a \ sed -i "s|CWS|8082|g" "${NGINX_CONFIG}"
proxy_set_header Accept-Encoding "";' "${NGINX_CONFIG}" sed -i "s|REPLACE_HOME|${HOME:-/root}|g" "${NGINX_CONFIG}"
cp "${NGINX_CONFIG}" /etc/nginx/sites-enabled # Correct image
sed -i "s|SUBFOLDER|/|g" "${NGINX_CONFIG}"
# Enable ingress
cp /etc/nginx/sites-available/ingress.conf /etc/nginx/sites-enabled