"Unable to connect to Home Assistant" via nginx reverse proxy

Yep, restarted after adding the docker IP.

Oops! Thank you, I took it out of the screenshot.

I’m using the jc21/nginx-proxy-manager Docker image on my NAS.

Changed my config to:

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 192.168.1.0/24 # Add the IP address of the proxy server
    - 172.20.0.0/24

But same problem. I get unable to connect to Home Assistant after entering credentials.

What is very strange is that I have my Google integration set up with this same domain and everything seems to work fine.

No iOS devices on my network.

1 Like

IP is not banned by HA correct?

maybe the nginx config is wrong. google does not connect in same manner.
Domain may be passing OK but websocket connections may be having issue.

Id look at nginx but not sure what to check there. Maybe try different addon or verify setup with someone using same addon

EDIT
Dont forget to change below back to normal when all is resolved.

Smells like websocket is not proxied on cloud flare, then

1 Like

Thanks all for the help. Cloudflare states that websockets are supported by default without any configuration changes. I’m fairly confident the problem is with how my nginx is working. I have Googled and tried some other solutions to get nginx to support websockets but nothing has worked. Unfortunately I don’t think this is worth the time and effort anymore. I have spent many hours so far and haven’t made much progress. I’m just going to go back to using duckdns to access home assistant.

Don’t give up! I’m having the same issue… It’s been working fine for AGES. Did something break during a recent upgrade?
Found my problem. My Lets Encrypt SSL Certs expired…months ago apparently and things just kept working until my system went offline for most of a day. Fixed my certs and it started working again.

My situation is similar: I am trying to access my local HA instance that is already accessible from outside the network using a duckdns domain using the Nginx Proxy Manager on a rented server. I am stuck with such a weird configuration because I don’t have a public ipv4 address.

I am getting the same errors that you described earlier. I found online, that setting

location / {
    proxy_pass http://homeassistant.local.hass.io:%%HA_PORT%%;
    proxy_set_header Host $host;
    proxy_redirect http:// https://;
    proxy_http_version 1.1;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
}

in Nginx is supposed to help with socket forwarding. I don’t know how to use it properly in NPM but maybe it helps you out or someone else has an idea?

Edit: this worked for me Home Assistant Community Add-on: Nginx Proxy Manager - #543 by JasonLee

5 Likes

I had exactly same problem and I’ve finally solved it by enabling WebSocket custom headers - $http_upgrade and $connection_upgrade - in reverse proxy (I’m using standard reverse proxy built in DSM, but I believe there is something similiar in Nginx Proxy Manager).

35 Likes

That solved my problem! Thanks much!

Thank you! This just solved an access issue for me after re-setting up NGINX.

1 Like

Thank you!! This solved my problem as well.

1 Like

Hi! Good to see you have it working. Can you please share how to add those headers to Nginx Proxy Manager? I also keep getting the “Unable to connect (…)” error after switching from the HA add-on Nginx (which was working) to the Proxy Manager that I have running on another device.

Although I have been trying for hours to get everything working before I posted, ofcourse just after posting I found the solution. I missed the checkbox of Websockets support. It’s working!

1 Like

Thank you so much! This solved my problem too!

Someone know how can I put this settings in the “Nginx Proxy Manager” please ?
I have same problem when I access from my work office PC (outside)
But it’s work when I use the mobile phone Android (outside)

In the Chrome console give me:
core.a0afd420.js:1 WebSocket connection to ‘wss://hass.xxxdomain.com/api/websocket’ failed:
(at my work office PC outside of my LAN)

Thanks a lot
Denis

1 Like

I just found this thread after having the same issue. I am using Cloudflare and nginx proxy manager. To get it working, go to nginx proxy manager and open the proxy host settings for the home assistant proxy you have configured. You will see the option there for Websockets support. Enable that and you should be good to go.

6 Likes

Looking everywhere and found this thread! Having same problem but don’t know how to apply the WebSocket custom header on Nginx Proxy Manager.
Please if someone could guide us

To get it working, go to nginx proxy manager and open the proxy host settings for the home assistant proxy you have configured. You will see the option there for Websockets support. Enable that and you should be good to go.

1 Like

I already have the websocket support enable… Dont know what else to try

Could be regarding the refresh tokens? I have a huge list and before this I was using another domain to connect

1 Like

Hi @barabasz
I am trying to include HA in my DSM reverse proxy with no luck so far. I would be grateful if you could provide some guidance.
Also, is DSM the best application, or do you recommend anything else?
Thanks in advance

I have similar problem but didn’t bother to look into it as I rarely need to access from outside the firewall. Finally today got a chance and got some insights from the posts above on proxy_set_header. To apply the two proxy_set_header rules in Nginx Reverse Proxy, add the following rules in Custom Location
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;

image

9 Likes

I am having this same issue except its only occuring when using Firefox. Chrome and Edge both connect fine through my domain. I’ve tried adding the set header commands to the location but it has no affect when using Firefox. Any ideas why this is happening?

edit

To add to this, running Firefox in Troubleshooting Mode fixes it.

edit2

It was uBlock Origin that was causing it. I disabled it and it works now.

1 Like