Initial upload
This commit is contained in:
86
recipes/system/nginx-proxy-path/install.sh
Normal file
86
recipes/system/nginx-proxy-path/install.sh
Normal file
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
ensure_root
|
||||
|
||||
NGINX_PATH="/srv/docker/nginx-php/nginx.conf"
|
||||
|
||||
if [ ! -f "$NGINX_PATH" ]; then
|
||||
log "Fehler: nginx-php scheint nicht installiert zu sein. Datei fehlt:"
|
||||
log "$NGINX_PATH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
read -p "Welcher Pfad soll erstellt werden? (Beispiel: /homeassistant): " LOCATION_PATH_RAW
|
||||
|
||||
# Normalize path
|
||||
LOCATION_PATH="${LOCATION_PATH_RAW#/}" # führenden "/" entfernen
|
||||
LOCATION_PATH="/${LOCATION_PATH}/" # sauber neu setzen /xyz/
|
||||
|
||||
echo ""
|
||||
read -p "Backend Zielserver (z.B. 192.168.3.21:8123): " PROXY_TARGET
|
||||
|
||||
echo ""
|
||||
echo "Konfiguration:"
|
||||
echo " NGINX-Pfad: $LOCATION_PATH"
|
||||
echo " Proxy Zielserver: $PROXY_TARGET"
|
||||
echo ""
|
||||
|
||||
# Konfliktprüfung
|
||||
if grep -q "location $LOCATION_PATH" "$NGINX_PATH"; then
|
||||
echo "WARNUNG: Ein Eintrag für diesen Pfad existiert bereits!"
|
||||
read -p "Überschreiben? (y/n): " OVERWRITE
|
||||
if [[ "$OVERWRITE" != "y" && "$OVERWRITE" != "Y" ]]; then
|
||||
log "Abgebrochen."
|
||||
exit 0
|
||||
fi
|
||||
# entferne bestehenden block
|
||||
$SUDO sed -i "\|location $LOCATION_PATH|,/}|d" "$NGINX_PATH"
|
||||
fi
|
||||
|
||||
read -p "Fortfahren und anwenden? (y/n): " CONFIRM
|
||||
if [[ "$CONFIRM" != "y" && "$CONFIRM" != "Y" ]]; then
|
||||
log "Abgebrochen."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Robust Proxy Block
|
||||
$SUDO tee -a "$NGINX_PATH" >/dev/null <<EOF
|
||||
|
||||
# Automatisch hinzugefügt: Reverse Proxy für $LOCATION_PATH
|
||||
location $LOCATION_PATH {
|
||||
proxy_pass http://$PROXY_TARGET/;
|
||||
|
||||
# Standard Header
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
|
||||
# WebSocket Support
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
|
||||
# Buffer & Timeout Tuning für Streams & Video
|
||||
proxy_read_timeout 3600;
|
||||
proxy_send_timeout 3600;
|
||||
proxy_buffering off;
|
||||
proxy_request_buffering off;
|
||||
client_max_body_size 0;
|
||||
|
||||
# Optional: Fließender Videoverkehr
|
||||
chunked_transfer_encoding on;
|
||||
}
|
||||
EOF
|
||||
|
||||
log "NGINX-Konfiguration erweitert."
|
||||
|
||||
(
|
||||
cd /srv/docker/nginx-php
|
||||
$SUDO docker compose restart nginx
|
||||
)
|
||||
|
||||
log "NGINX neu geladen."
|
||||
log "Aufruf nun möglich unter: http://<server-ip>$LOCATION_PATH"
|
||||
Reference in New Issue
Block a user