Cannot use android companion through NginX (browser works fine)

Context:
I have been working successfully with home assistant for some time. Connecting through browser has never given me any issue. Recently I have decided to try the android app.

Problem:
Android App gives a blank screen when trying to connect to home assistant (through nginx). When exposing home assistant port and connecting directly it works fine.

Setup:
I have docker images running nginx and home assistant. Obviously only nginx is exposed to the outside world.

nginx.conf

    server { # home_assistant
        listen       443 ssl;
        ssl_certificate /etc/ssl/some.crt;
        ssl_certificate_key /etc/ssl/some.key;
        server_tokens off;
        server_name  home_assistant mysubdomain.duckdns.org;
        access_log   /var/log/nginx/home_assistant.access.log  main;
        root         html;
        
        location / {
            proxy_pass http://home_assistant:8123;
            proxy_set_header Upgrade $http_upgrade;	# required for websocket forwarding
            proxy_set_header Connection "Upgrade";  # required for websocket forwarding
        }
    }

Home Assistant version: image: homeassistant/home-assistant:0.103.5
Home Assistant companion version: 1.4.0

Thank you all for the support, you are an awesome community

For me nginx with HA Companion works.

Try this:

server {
        listen 443 ssl;
        server_name xxx.xxx.de; # Domain für die erste Web-Applikation

        ssl on;
        ssl_certificate /etc/letsencrypt/live/xxxx/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/xxxx/privkey.pem; # managed by Certbot

        # Manche Web-Applikationen leiten einen auf http:// um. Die nachfolgende Anweisung leitet http:// anfragen an Port 443 auf https:// um
        error_page 497 = https://$server_name:$server_port$request_uri;

        location /
               {
                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header Host $host;
                proxy_http_version 1.1;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass http://192.168.50.4:5010; # Interne IP und Port
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
               }

}
2 Likes