Nginx Reverse Proxy Set Up Guide – Docker

hey mate, sorry for bothering you, but wich advanced section do you mean? i want to try this fix because with the old versions it worked without a problem. Even my other forwarded sites a working like a charm with the new Update. Only home assistant is not working correctly. I also did the thing with the trusted Proxies but no chance.

Below are some screenshots on how to get to the Advanced section I was referring to. (I don’t post much so pardon this messy post if it doesn’t come through right, ha).



You may notice I commented out the resolver line, I’m not sure that was necessary but I think it prevented the proxy from coming back online in my particular case. The final screenshot doesnt show all the text in that advanced box but my previous post has all the text that I put in there.

Hope this helps.

I’m using Home Assistant Core with Nginx Proxy Manager, both installed as Docker containers on a Pi 4. Everything worked fine remotely with SSL enabled, etc.

I’ve gotten the ‘Unable to connect to Home Assistant’ warning before and was able to get it to work with only enabling the ‘Websockets Support’ toggle in Nginx Proxy Manager (as can be seen in @cmille34’s post right above).

Recently the same error (‘Unable to connect to Home Assistant’) showed up again. In the browser console it also showed an error on wss://my.domain.com/api/websocket, which didn’t make sense since the toggle in Nginx Proxy Manager is on.

After adding only the following under ‘Advanced’ in Nginx Proxy Manager (again, see the screenshots above) everything started to work again:

location /api/websocket {
    proxy_pass http://192.168.1.1:8123;
}

So, in my case it looks like the ‘Websockets Support’ toggle doesn’t actually set this. I still need to confirm this by looking in the generated .conf file for Home Assistant in the Nginx Proxy Manager Docker container though.

Hello!

I have installed a clean Hass.io 2021.8.5, and I use the Nginx Proxy Manager addon to redirect to all my resources and get a certificate. But I ran into a problem connecting to the Home Assistant by domain name.

My HTTP configuration:

http:
  use_x_forwarded_for: true
  trusted_proxies:
    - 127.0.0.1
    - 172.30.32.0/24
    - 172.30.33.0/24

My configuration Nginx Proxy Manager:


But the problem persists, after logging in, I get an error message:
Unable to connect to Home Assistant.

And the server log is empty.
Please tell me how to fix this?

This is the right answer. thanks!

Juan, thank you for making available in tutorial form all the time spent previously. Well, I think this is a tip for the experts, I understand that there are many people who are lazy to read, and find it easier to ask. However, there are things that are not always easy to understand, and sometimes a simple tip can open the way to full understanding. Once again I thank you because everything worked perfectly. :clap:

Welcome Marcio. Glad it still helps people

1 Like

Hi Juan,

Thank you for taking the time to share your learning and the detailed instruction with people like me, who struggle with HA setup in Ubuntu based server (20.04). I was able to follow it for the most part, but I don’t think I did everything right to get it working 100%. The good news is my subdomain (hass.mydomain.duckdns.org) is pointing to my server. The bad news is I can’t connect to it thru HTTPS. The only way I can connect to it is http://hass.mydomain.duckdns.org:8123. Do you have an idea what I might be missing and how I can fix it? Thanks in advance!

You say you were able to follow “most”. What did you do different?
When I put this together a few years ago I was also in Ubuntu. So it should do the same.

Hi Juan,

I followed youre guide to setup the SWAG container but something is not working as it should.
I can reach my site on http and https by using homeassistant.mydomain.duckdns.org.

i get the login screen but after that it keeps saying loading and it stays there.
In the nginx log i keep getting:

[error] 495#495: *23 homeassistant could not be resolved (3: Host not found), client: 192.168.1.1, server: homeassistant.*, request: "GET /api/websocket HTTP/1.1", host: "homeassistant.Mydomain.duckdns.org"

The strange thing is i dont have a network which contains a 192.168.1.x network.

my homeassistant.subdomain.conf

## Version 2021/10/11
# make sure that your dns has a cname set for homeassistant and that your homeassistant container is not using a base url

# As of homeassistant 2021.7.0, it is now required to define the network range your proxy resides in, this is done in Homeassitants configuration.yaml
# https://www.home-assistant.io/integrations/http/#trusted_proxies
# Example below uses the default dockernetwork ranges, you may need to update this if you dont use defaults.
#
# http:
#   use_x_forwarded_for: true
#   trusted_proxies:
#     - 172.16.0.0/12

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

    server_name homeassistant.*;

    include /config/nginx/ssl.conf;

    client_max_body_size 0;

    # enable for ldap auth, fill in ldap details in ldap.conf
    #include /config/nginx/ldap.conf;

    # enable for Authelia
    #include /config/nginx/authelia-server.conf;

    location / {
        # enable the next two lines for http auth
        #auth_basic "Restricted";
        #auth_basic_user_file /config/nginx/.htpasswd;

        # enable the next two lines for ldap auth
        #auth_request /auth;
        #error_page 401 =200 /ldaplogin;

        # enable for Authelia
        #include /config/nginx/authelia-location.conf;

        include /config/nginx/proxy.conf;
        include /config/nginx/resolver.conf;
        set $upstream_app 192.168.2.xxx;
        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 homeassistant;
        set $upstream_port 8123;
        set $upstream_proto http;
        proxy_pass $upstream_proto://$upstream_app:$upstream_port;
    }
}

Can you shed some light on what i can do?

I have never been able to get the default homeassistant config file included with swag to work properly.

My suggestion would be to follow the directions in the top post of this guide and modify the default nginx config file instead. My working example is in this post higher in the thread.

There is a newer version of this guide that helped me configure remote access to HomeAssistant. I’m linking it here in case others will find it usefull.
Remote access with Docker

1 Like