Trotz Reverse Proxy: Connection refused from the non-local address

Begonnen von heikoh81, 06 Dezember 2025, 12:10:43

Vorheriges Thema - Nächstes Thema

heikoh81

Hallo zusammen,

ich habe eine fhem-Instanz (debian, nicht dockerized) auf einem VPS laufen, der auch als Mail-, Web- und VPN-Server bei mir fungiert.
Fhem ist hinter einem Nginx-Reverse-Proxy mit BasicAuth geschaltet:
    location /fhem {
        set $my_http_upgrade "";
        set $my_connection "Connection";
        if ($http_upgrade = "websocket") {
          set $my_http_upgrade $http_upgrade;
          set $my_connection "upgrade";
        }
        proxy_set_header Upgrade $my_http_upgrade;
        proxy_set_header Connection $my_connection;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Host $host:$server_port;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 2073600;
        proxy_buffering off;
        proxy_pass http://localhost:8083/fhem;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
    }

Das funktioniert auch, d.h. bei aufruf der URL kommt eine BasicAuth abfrage.

Da BasicAuth ja nicht mehr so Stand der Technik ist, habe ich vor Monaten einen dockerized NginxProxyManager mit Authelia davor geschaltet, um so eine Art SingleSignOn für meine Applikationen zu haben.
Das funktioniert auch alles, inklusive Fail2Ban usw., und dennoch habe ich das hier im log:

2025.12.06 11:58:40 1: Connection refused from the non-local address 93.174.95.106:59434, as there is no working allowed instance defined for it
2025.12.06 11:58:40 1: Connection refused from the non-local address 93.174.95.106:59460, as there is no working allowed instance defined for it
2025.12.06 11:58:41 1: Connection refused from the non-local address 93.174.95.106:59574, as there is no working allowed instance defined for it
2025.12.06 11:58:41 1: Connection refused from the non-local address 93.174.95.106:59600, as there is no working allowed instance defined for it
2025.12.06 11:58:41 1: Connection refused from the non-local address 93.174.95.106:59658, as there is no working allowed instance defined for it

Ich verstehe überhaupt nicht, wie das überhaupt zu fhem durchkommt. fhem sollte nur port 8083 offen haben, warum reagiert das überhaupt auf die hier gezeigten ports?

define WEB FHEMWEB 8083 global
setuuid WEB 65.......
attr WEB JavaScripts codemirror/fhem_codemirror.js
attr WEB csrfToken none
attr WEB editConfig 1
attr WEB longpoll 1

Ich habe jetzt mal das "global" testweise entfernt & werde das Log beobachten.
Dennoch verstehe ich nicht, wieso fhem überhaupt auf die ganzen Ports lauscht.

Viele Grüße,
Heiko

betateilchen

#1
Diese ports im 50.000er Bereich sind temporäre interne Verbindungen, die von FHEM benötigt werden.
Die sieht man prinzipiell in jedem FHEM, wenn man "list TYPE=FHEMWEB" eingibt:
Diese Verbindungen entstehen und verschwinden von alleine wieder.

Bei mir sieht das aktuell beispielsweise so aus:

web_longpoll
web_longpoll_192.168.123.162_59839
web_longpoll_192.168.123.162_59840
web_longpoll_192.168.123.162_59842
web_longpoll_192.168.123.162_59843
web_longpoll_192.168.123.162_59844
-----------------------
Formuliere die Aufgabe möglichst einfach und
setze die Lösung richtig um - dann wird es auch funktionieren.
-----------------------
Lesen gefährdet die Unwissenheit!

heikoh81

#2
Danke für deine schnelle Antwort.
Vorweg: Seit ich in der DEF 8083 global auf nur 8083 geändert habe, gibt es keine solchen Log-Einträge mehr.

Bzgl. der 50000er-Ports:
Ich habe leider auch Zugriffe bei niedrigeren Ports, sieht irgendwie nach Portscans aus:
2025.12.01 00:51:54 1: Connection refused from the non-local address 79.124.49.90:50124, as there is no working allowed instance defined for it
2025.12.01 01:26:29 1: Connection refused from the non-local address 162.142.125.125:1922, as there is no working allowed instance defined for it
2025.12.01 01:26:29 1: Connection refused from the non-local address 162.142.125.125:1942, as there is no working allowed instance defined for it
2025.12.01 01:26:29 1: Connection refused from the non-local address 162.142.125.125:1946, as there is no working allowed instance defined for it
2025.12.01 01:26:29 1: Connection refused from the non-local address 162.142.125.125:1948, as there is no working allowed instance defined for it
2025.12.01 01:26:33 1: Connection refused from the non-local address 162.142.125.125:2038, as there is no working allowed instance defined for it
2025.12.01 01:26:36 1: Connection refused from the non-local address 162.142.125.125:2084, as there is no working allowed instance defined for it
2025.12.01 07:38:02 1: Connection refused from the non-local address 167.94.138.116:8824, as there is no working allowed instance defined for it
2025.12.01 07:38:02 1: Connection refused from the non-local address 167.94.138.116:8834, as there is no working allowed instance defined for it
2025.12.01 07:38:03 1: Connection refused from the non-local address 167.94.138.116:11590, as there is no working allowed instance defined for it
2025.12.01 07:38:03 1: Connection refused from the non-local address 167.94.138.116:11606, as there is no working allowed instance defined for it
2025.12.01 07:38:12 1: Connection refused from the non-local address 167.94.138.116:38262, as there is no working allowed instance defined for it
2025.12.01 10:41:44 1: Connection refused from the non-local address 198.235.24.64:61954, as there is no working allowed instance defined for it
2025.12.01 10:41:45 1: Connection refused from the non-local address 198.235.24.64:61970, as there is no working allowed instance defined for it
2025.12.01 15:59:55 1: Connection refused from the non-local address 203.55.131.4:53802, as there is no working allowed instance defined for it
2025.12.01 16:16:10 1: Connection refused from the non-local address 203.55.131.4:38150, as there is no working allowed instance defined for it
2025.12.01 18:36:11 1: Connection refused from the non-local address 45.135.193.9:46070, as there is no working allowed instance defined for it

Ich habe für einen abgeschlossenen Monat mehr als 1000 solche Zeilen gehabt.

"list TYPE=FHEMWEB" ergibt aktuell (ohne global):
WEB
WEB_127.0.0.1_51772
WEB_127.0.0.1_58006
So ist es ja in Ordnung.

Viele Grüße,
Heiko

Otto123

#3
Hallo Heiko,

da ich dein exaktes Setup nur ahnen kann:
mit global bindet FHEM die 8083 an alle Netzwerkschnittstellen: 0.0.0.0:8083 beantwortet aber eigentlich nur Anfragen aus privaten Netzwerken (siehe help FHEMWEB - allowfrom Attribute, dein Log zeigt: es hat genauso gewirkt  ;) )
ohne global bindet FHEM die 8083 an 127.0.0.1:8083
Die Portbindungen kannst Du Dir z.B. mit ss -lntu anschauen.
Insofern sollten jetzt die Logeinträge in FHEM vom 1.12. Geschichte sein.

Dein Proxy wirkt als Sicherheitsschleuse natürlich nicht für "alles" was an die öffentliche IP gebunden ist. Du solltest also darauf achten, dass nur Port 80 und 443 von deinem Proxy an die öffentliche IP gebunden sind. Alles andere sollte nur intern lauschen, ansonsten sind alle Prozesse die öffentlich lauschen potentiell angreifbar.

Gruß Otto
Viele Grüße aus Leipzig  ⇉  nächster Stammtisch an der Lindennaundorfer Mühle
RaspberryPi B B+ B2 B3 B3+ ZeroW,HMLAN,HMUART,Homematic,Fritz!Box 7590,WRT3200ACS-OpenWrt,Sonos,VU+,Arduino nano,ESP8266,MQTT,Zigbee,deconz

passibe

#4
Zitat von: heikoh81 am 06 Dezember 2025, 12:10:432025.12.06 11:58:40 1: Connection refused from the non-local address 93.174.95.106:59434, as there is no working allowed instance defined for it
Das sind einfach die clientseitigen Ports. Du brauchst ja immer Ports auf beiden Seiten, d.h. FHEM "hört" auf 8083 (bzw. nginx auf 443), aber der Client, der sich verbindet, verbindet sich auch von einem Port aus. Sonst könnte er ja nichts senden. Das sind typischerweise eben diese hohen 40000-50000er Ports.
Dass du auch Traffic von Clients mit niedrigeren Ports siehst liegt daran, dass die die einfach benutzen, weil das irgendwelche bösartigen Bots oder harmlose Scanner (z.B. censys) sind. Schau dir einfach mal an, was das für IPs sind (https://ipinfo.io/<IP>) und dann siehst du das.
Wenn du willst kannst du mit Tools wie crowdsec oder irgendwelchen Blocklisten (dann mit iptables mit ipset) diese Zugriffe ein bisschen blockieren, wirklich sicherer macht das deinen Server aber nicht, sondern hält nur die Logs sauber. Cloudflare proxying davor setzen geht aber auch (dann sehen die halt deinen Traffic).



Zum ursprünglichen Problem mit Authelia:
Erstmal ist diese nginx config (du hast die vermutlich vom wiki?) ein bisschen zu kompliziert, wie wir inzwischen herausgefunden haben. Inzwischen reicht eigentlich folgendes in der location directive:
# Ensure Websocket proxying works
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";

# Standard reverse proxy headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

set $upstream 127.0.0.1:8083;
proxy_pass http://$upstream;
Wichtig ist auf jeden Fall auch, dass du $upstream verwendest und nicht unmittelbar in proxy_pass die IP/den Hostnamen angibst, weil nginx sonst nicht startet, sollte FHEM einmal nicht verfügbar sein (siehe hier).

Ansonsten scheint es irgendwie so, als wäre Port 8083 nicht blockiert oder nginx macht irgendwas komisches und proxied TCP traffic? Ich bin mir zu 99% sicher, dass FHEM da auch nicht irgendwie X-Forwarded-For auswertet, sondern das Blockieren ausschließlich auf dem TCP-Layer stattfindet. Also – wenn alles richtig konfiguriert ist – kann es eigentlich nicht sein, dass diese IPs in FHEM auftauchen, weil sie gar nicht in der Lage sein sollten, FHEM auf TCP-Ebene zu erreichen.

Ich hoffe du hast auch in deinem FHEMWEB-Device
allowfrom 127\.0\.0\.1 gesetzt, sonst hast du grade nämlich extrem viel Glück, dass die Standardkonfiguration so schlau ist non-RFC1918-IPs per Default abzuweisen und dein FHEM grade nicht offen im Netz hängt.
Deshalb solltest du übrigens, auch wenn nginx die Authentifizierung übernimmt, FHEM immer noch mittels eines allowed-Devices (also basicauth) absichern. nginx kann dann einfach beim proxyen den entsprechenden Header an FHEM senden (d.h. der Client kriegt von der im Hintergrund immer noch stattfindenden basicauth nichts mit), aber dann hast du neben der Abweisung von non-RFC1918-Adressen noch eine Verteidigungslinine, sollte – wie jetzt – FHEM doch irgendwie direkt erreichbar sein. Das hilft auch (bedingt) gegen SSRF.
Geht in nginx mit:
proxy_set_header Authorization "Basic <user:pass in base 64>(<user:pass in base 64> kriegt man mit echo -n 'user:pass' | base64)

EDIT: Mir fällt grade ein, eine Firewall braucht es dann nicht (zwingend), wenn auf dem jeweiligen Port nichts lauscht (klick). Bitte deshalb natürlich auch global aus jeglichen FHEMWEB-Definitionen entfernen. Dann hat nur noch localhost (hier u.a. nginx) Zugriff. Das dürfte übrigens schon der "hotfix" sein, der das erstmal halbwegs sinnvoll absichert.

Um jetzt die Lösung für dein Problem zu finden, poste bitte mal deine Firewall-Konfiguration und deine nginx-Konfiguration (möglichst vollständig) so wie sie jetzt mit authelia ist.

(Wie du siehst, gibt es vielleicht doch einige Fallstricke hier; deshalb wäre mE auch grundsätzlich zu überdenken, ob du FHEM wirklich komplett ins Netz stellen willst und nicht lieber nginx so konfigurieren willst, dass es nur IPs aus deinem VPN-Subnetz auf FHEM lässt ... Ist dann zwar vielleicht nicht so komfortabel, aber es dürfte ruhigeren Schlaf erlauben. Selektiv irgendwelche Endpoints für Webhooks freigeben (Geofency o.ä.) kann man dann immer noch; die hätten dann aber auch nur die notwendigen Berechtigungen und es wäre eben nicht die volle FHEM-Installation. Grundvoraussetzung ist aber sowieso, dass die Firewall richtig konfiguriert ist. Sonst bringt das mit dem VPN auch nix.)

rudolfkoenig

ZitatIch bin mir zu 99% sicher, dass FHEM da auch nicht irgendwie X-Forwarded-For auswertet,
Nein tut es nicht, ich tippe darauf, dass der "allowfrom" Code uns beiden geholfen hat.
Heiko, dass er nicht gehackt, und mir, dass ich nicht auf dem Pranger gestellt wurde.

heikoh81

Hallo zusammen,

erstmal danke für eure sehr ausführlichen Antworten.
Und danke, dass fhem so schlau war, die nicht-lokalen Zugriffsversuche zu verwerfen.

Dass ich überhaupt "global" angefügt hatte, ist ein Fehler meinerseits. Ich habe vor Monaten ein "Backup-System" des VPS auf meinem häuslichen Proxmox gebaut, falls es mal Probleme mit dem VPS gibt. Aus irgendwelchen Gründen ist da ein "global" in die config reingerutscht - was ich auch kommentiert, aber offensichtlich vergessen hatte.
WEB war auch schon mit attr basicAuth gesichert, aber ebenfalls auskommentiert aufgrund der Proxmox-Versuche...

Dass fhem überhaupt auf meinem VPS mitläuft (per fhem-telnet an meine häusliche Hauptinstanz über Wireguard angebunden) hat eine noch längere Geschichte und stammt aus der Zeit, als fhem noch auf einem Raspi1 (!) lief. Der hatte nicht genug Rechenpower for dblog (plus MicroSD-Verschleiss) und IPCam, das mir bei Bewegungsmelder-Auslösung Fotos von Webcams per Mail schickt. Deshalb habe ich das auf den VPS ausgelagert. Geändert habe ich das dann seither nicht mehr...

Kommen wir zum Punkt "Firewall". Ich habe keine Firewall explizit installiert, und mein Hoster netcup bietet keine vorgeschaltete zentral konfigurierbare an.
ip6tables -L -n liefert:
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
DOCKER-USER  0    --  ::/0                 ::/0
DOCKER-FORWARD  0    --  ::/0                 ::/0

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain DOCKER (0 references)
target     prot opt source               destination

Chain DOCKER-BRIDGE (1 references)
target     prot opt source               destination

Chain DOCKER-CT (1 references)
target     prot opt source               destination

Chain DOCKER-FORWARD (1 references)
target     prot opt source               destination
DOCKER-CT  0    --  ::/0                 ::/0
DOCKER-ISOLATION-STAGE-1  0    --  ::/0                 ::/0
DOCKER-BRIDGE  0    --  ::/0                 ::/0

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target     prot opt source               destination

Chain DOCKER-ISOLATION-STAGE-2 (0 references)
target     prot opt source               destination

Chain DOCKER-USER (1 references)
target     prot opt source               destination

fhem wird nativ ausgeführt, ebenso ein nginx, der eben diese fhem-installation über eine Subdomain von außen erreichbar macht, geschützt durch Reverse Proxy mit basicauth & fail2ban (Port 4443).
Später kam dann NginxProxyManager (NPM) & Authelia hinzu, die aber dockerized laufen. Das ist auch der Grund, warum der native nginx noch läuft: NPM konnte keinen Proxy auf das native fhem machen, zumindest habe ich es nicht hinbekommen. Dieser native nginx macht auch noch einen Reverse Proxy auf PHPMyAdmin & Roundcube, weil die eben historisch ebenfalls noch nativ und nicht dockerized laufen.
Ich habe hier das Problem, dass dockerized NPM zwar meine Dienste im Heimnetz via Wireguard nach außen durchreichen kann (d.h. auf "anderen" Hosts), aber nicht das, was auf "localhost" läuft. Vielleicht hat jemand eine Lösung, dann kann ich den nativen nginx in Rente schicken.

ss -lntu liefert.
Erläuterung:
  • Auf dem VPS läuft ein Mailserver basierend auf iredmail, roundcube ist hinter reverse-Proxy
  • 4443 ist von dem nativ laufenden nginx
  • Wireguard auf 51820, 51821, 51822, 51823, 51824
  • 9091 ist von authelia
  • 52622 ist mein manueller sshd-Port, sshd nimmt Verbindungen per /etc/hosts.allow /etc/hosts.deny nur von innen an.
Netid          State           Recv-Q          Send-Q                    Local Address:Port                      Peer Address:Port          Process
udp            UNCONN          0               0                               0.0.0.0:47890                          0.0.0.0:*
udp            UNCONN          0               0                               0.0.0.0:68                             0.0.0.0:*
udp            UNCONN          0               0                               0.0.0.0:41547                          0.0.0.0:*
udp            UNCONN          0               0                               0.0.0.0:51820                          0.0.0.0:*
udp            UNCONN          0               0                               0.0.0.0:51822                          0.0.0.0:*
udp            UNCONN          0               0                                  [::]:51820                             [::]:*
udp            UNCONN          0               0                                  [::]:51822                             [::]:*
tcp            LISTEN          0               100                           127.0.0.1:7790                           0.0.0.0:*
tcp            LISTEN          0               100                           127.0.0.1:7791                           0.0.0.0:*
tcp            LISTEN          0               5                             127.0.0.1:7778                           0.0.0.0:*
tcp            LISTEN          0               5                             127.0.0.1:7779                           0.0.0.0:*
tcp            LISTEN          0               5                             127.0.0.1:7777                           0.0.0.0:*
tcp            LISTEN          0               100                             0.0.0.0:587                            0.0.0.0:*
tcp            LISTEN          0               1000                          127.0.0.1:24242                          0.0.0.0:*
tcp            LISTEN          0               4096                          127.0.0.1:8000                           0.0.0.0:*
tcp            LISTEN          0               4096                            0.0.0.0:9091                           0.0.0.0:*
tcp            LISTEN          0               4096                          127.0.0.1:9998                           0.0.0.0:*
tcp            LISTEN          0               4096                          127.0.0.1:783                            0.0.0.0:*
tcp            LISTEN          0               500                             0.0.0.0:993                            0.0.0.0:*
tcp            LISTEN          0               100                             0.0.0.0:995                            0.0.0.0:*
tcp            LISTEN          0               4096                          127.0.0.1:10026                          0.0.0.0:*
tcp            LISTEN          0               4096                          127.0.0.1:10027                          0.0.0.0:*
tcp            LISTEN          0               4096                          127.0.0.1:10024                          0.0.0.0:*
tcp            LISTEN          0               100                           127.0.0.1:10025                          0.0.0.0:*
tcp            LISTEN          0               100                           127.0.0.1:10028                          0.0.0.0:*
tcp            LISTEN          0               32                            127.0.0.1:8083                           0.0.0.0:*
tcp            LISTEN          0               100                           127.0.0.1:4190                           0.0.0.0:*
tcp            LISTEN          0               4096                          127.0.0.1:8284                           0.0.0.0:*
tcp            LISTEN          0               4096                          127.0.0.1:81                             0.0.0.0:*
tcp            LISTEN          0               500                             0.0.0.0:143                            0.0.0.0:*
tcp            LISTEN          0               100                           127.0.0.1:24                             0.0.0.0:*
tcp            LISTEN          0               80                            127.0.0.1:3306                           0.0.0.0:*
tcp            LISTEN          0               100                             0.0.0.0:25                             0.0.0.0:*
tcp            LISTEN          0               4096                          127.0.0.1:9443                           0.0.0.0:*
tcp            LISTEN          0               100                             0.0.0.0:110                            0.0.0.0:*
tcp            LISTEN          0               4096                            0.0.0.0:80                             0.0.0.0:*
tcp            LISTEN          0               4096                            0.0.0.0:443                            0.0.0.0:*
tcp            LISTEN          0               128                             0.0.0.0:52622                          0.0.0.0:*
tcp            LISTEN          0               511                             0.0.0.0:4480                           0.0.0.0:*
tcp            LISTEN          0               511                             0.0.0.0:4443                           0.0.0.0:*
tcp            LISTEN          0               100                                [::]:587                               [::]:*
tcp            LISTEN          0               4096                               [::]:9091                              [::]:*
tcp            LISTEN          0               500                                [::]:993                               [::]:*
tcp            LISTEN          0               100                                [::]:995                               [::]:*
tcp            LISTEN          0               500                                [::]:143                               [::]:*
tcp            LISTEN          0               100                                [::]:25                                [::]:*
tcp            LISTEN          0               100                                [::]:110                               [::]:*
tcp            LISTEN          0               4096                               [::]:80                                [::]:*
tcp            LISTEN          0               4096                              [::1]:783                               [::]:*
tcp            LISTEN          0               4096                               [::]:443                               [::]:*
tcp            LISTEN          0               128                                [::]:52622                             [::]:*


Das native nginx, das fhem nach außen erreichbar macht, habe ich so angepasst, wie von dir vorgeschlagen:
# HTTPS
server {
listen 4443 ssl;
server_name server2.xyz.de;

    root /var/www/xyz.de/html;
    index index.php index.html;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;

#####HEIKO 17.04.2018 Reverse Proxy fuer FHEM auf VServer Anfang#####
    location /fhem {
##HEIKO neu 08.12.2025 gemaess https://forum.fhem.de/index.php?topic=143247
# Ensure Websocket proxying works
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";

# Standard reverse proxy headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

set $upstream 127.0.0.1:8083;
proxy_pass http://$upstream;
auth_basic "Restricted Content";
auth_basic_user_file /etc/nginx/.htpasswd;
    }
#####HEIKO 17.04.2018 Reverse Proxy fuer FHEM auf VServer Ende#####

########################################################
########################################################

    include /etc/nginx/templates/misc.tmpl;
    include /etc/nginx/templates/ssl.tmpl;
    include /etc/nginx/templates/iredadmin.tmpl;
    include /etc/nginx/templates/roundcube.tmpl;
    include /etc/nginx/templates/sogo.tmpl;
    include /etc/nginx/templates/netdata.tmpl;
    include /etc/nginx/templates/php-catchall.tmpl;

}

Und das hier ist die Konfiguration im NPM - die Subdomain ist fhemvs.xyz.de:
location /authelia {
    internal;
    set $upstream_authelia http://authelia-authelia-1:9091/api/verify;
    proxy_pass_request_body off;
    proxy_pass $upstream_authelia;   
    proxy_set_header Content-Length "";
 
    # Timeout if the real server is dead
    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
    client_body_buffer_size 128k;
    proxy_set_header Host $host;
    proxy_set_header X-Original-URL $scheme://$http_host$request_uri;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host $http_host;
    proxy_set_header X-Forwarded-Uri $request_uri;
    proxy_set_header X-Forwarded-Ssl on;
    proxy_redirect  http://  $scheme://;
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_cache_bypass $cookie_session;
    proxy_no_cache $cookie_session;
    proxy_buffers 4 32k;
    send_timeout 5m;
    proxy_read_timeout 240;
    proxy_send_timeout 240;
    proxy_connect_timeout 240;
}
 
    location / {
        set $upstream_fhemvs https://server2.xyz.de:4443;
        proxy_pass $upstream_fhemvs;
        auth_request /authelia;
        auth_request_set $target_url $scheme://$http_host$request_uri;
        auth_request_set $user $upstream_http_remote_user;
        auth_request_set $groups $upstream_http_remote_groups;
        proxy_set_header Remote-User $user;
        proxy_set_header Remote-Groups $groups;
proxy_set_header Authorization "Basic GEHEIMgeheimGEHEIM";
        error_page 401 =302 https://auth.xyz.de/?rd=$target_url;
        #####client_body_buffer_size 128k;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
        send_timeout 5m;
        proxy_read_timeout 360;
        proxy_send_timeout 360;
        proxy_connect_timeout 360;
        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;
        proxy_set_header X-Forwarded-Host $http_host;
        proxy_set_header X-Forwarded-Uri $request_uri;
        proxy_set_header X-Forwarded-Ssl on;
        proxy_redirect  http://  $scheme://;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_cache_bypass $cookie_session;
        proxy_no_cache $cookie_session;
        #####proxy_buffers 64 256k;
        set_real_ip_from 192.168.178.0/16;
        set_real_ip_from 172.0.0.0/8;
        real_ip_header X-Forwarded-For;
        real_ip_recursive on;
proxy_buffering off;
    }

Viele Grüße,
Heiko