502 Bad Gateway on custom domain, local ip gives no problem

Dear,

I got HASS running on a VM on my unraid server (see setup below)
All is working fine localy, however when i want to acces my HASS throughout my custom domain (like nabu casa) it connects for 20 seconds and then gives a timeout and a 502 error.
I connect it throughout a reverse proxy (Swag → Letsencrypt) that has an Nginx server running.
All the other apps i use with this setup have no isue’s so far. Anyone got an idea how i could debug this or what the problem could be ?

See the setup and settings below.

Firewall portforward:

VM Setup in Unraid

For security reasons i’ve set my domain to xxx.xx (not gonne give away my real domain) ^^

HASS config concerning the HTTP stuff

##########################################
##         HASS Default settings        ##
##########################################
homeassistant:
  name: Cribzz
  external_url: "https://homeassistant.xxx.xx"
  internal_url: "http://homeassistant.local:8123"
  latitude: !secret homeassistant_latitude
  longitude: !secret homeassistant_longitude
  elevation: !secret homeassistant_elevation
  unit_system: metric
  temperature_unit: C
  time_zone: Europe/Brussels
  currency: EUR
  packages: !include_dir_named include
  allowlist_external_dirs: [/config/]
  media_dirs:
    local: /media


##########################################
##                 HTTP                 ##
##########################################
http:
  cors_allowed_origins:
    - https://google.com
    - https://www.home-assistant.io
    - https://homeassistant.xxx.xx
  use_x_forwarded_for: true
  trusted_proxies:
    - 192.168.0.2
    - 192.168.0.130
    - 172.0.0.1
  ip_ban_enabled: true
  login_attempts_threshold: 5

SWAG proxy config for the reverse proxy

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name homeassistant.*;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    location / {
    	   proxy_set_header Upgrade $http_upgrade;
    	   proxy_set_header Connection "upgrade"; 
        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app 192.168.0.130;
        set $upstream_port 8123;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;

    }

    location /api {
        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app 192.168.0.130;
        set $upstream_port 8123;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;
    }

    location /local {
        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app 192.168.0.130;
        set $upstream_port 8123;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;
    }
}

If you need more info feel free to ask, thanks in advance!

No idea if it will help you but here is my site conf.

I have this is configuration.yaml

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 172.16.0.0/12
    - 192.168.1.3

And my swag site conf:

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    server_name homeassistant.*;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

        error_page 401 $scheme://domain.com/api/v2/organizr/error/$status?return=$request_uri;
        error_page 400 402 403 404 405 408 500 502 503 504  $scheme://domain.com/api/v2/organizr/error/$status;

location / {
        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app 192.168.1.25;
        set $upstream_port 8123;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;

    }

    location ~ ^/(api|local|media)/ {
        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app 192.168.1.25;
        set $upstream_port 8123;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;
    }
}

Searg!

Thanks for the info, how ever my config (or yours which is better than mine) didn’t resolve the isue.
I’ve been debugging for a while now and finaly came to the conclusion that my docker Plex image is cause the disconnect isue … i’m looking into this and will post the fix when i find it.

Although thanks for the help!

Kind regards

Any luck finding a solution?

same issue here… no solution??

Hey its been a while since i had this problem but i recal correctly i reinstalled HASS fully. I’ve also changed my router / portforwarding and even my reverse proxy setup in the mean while. I’m sorry but i can’t recal which solutuion fixed this isue.

Just in case anyone stumbles into this topic looking for a solution like me, it turns out I had Nginx pointed to the httpS location on my local network, obviously this does not exist (in my case) so I changed the setting to http and presto it worked…

1 Like

Thank you so much!!!