Dataplicity & nginx -> Home Assistant

I am trying to access my home assistant remotely by installing dataplicity & nginx and I am at that point, when i type https://xxxxxxxxxx.dataplicity.io/ I have access to my nginx server.


The tricky part is that I am not sure how to proceed further since every change that I make then my server goes No Response.

Any help would be much appreciated.

PS. The reason I am using this method is that the port forwarding option does not work for me because of ISP restrictions.

What does your nginx setup look like?

~Cheers

I am following this guide https://home-assistant.io/docs/ecosystem/nginx/ , except that I am skipping step 3 & 4 (since dataplicity has ssl) and also removing the part below.

server {
    # Update this line to be your domain
    server_name example.com;

    # Ensure these lines point to your SSL certificate and key
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    # Use these lines instead if you created a self-signed certificate
    # ssl_certificate /etc/nginx/ssl/cert.pem;
    # ssl_certificate_key /etc/nginx/ssl/key.pem;

    # Ensure this line points to your dhparams file
    ssl_dhparam /etc/nginx/ssl/dhparams.pem;


    # These shouldn't need to be changed
    listen [::]:443 default_server ipv6only=off; # if your nginx version is >= 1.9.5 you can also add the "http2" flag here
    add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
    ssl on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;

If that is your whole config you are missing the actual reverse proxy part of that tutorial. Which is

location / {
        proxy_pass http://localhost:8123;
        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;
    }

~Cheers

The one I posted above is the one that I am removing while this is how my config looks like:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    # Update this line to be your domain
    server_name example.com;

    # These shouldn't need to be changed
    listen [::]:80 default_server ipv6only=off;
    return 301 https://$host$request_uri;
}

proxy_buffering off;

    location / {
        proxy_pass http://localhost:8123;
        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;
    }
}

Found the solution.

After installing nginx, all I had to do was paste this config to directory /etc/nginx/sites-enabled/default

server {
    listen 80;
    server_name yourapp.com; # or server_name subdomain.yourapp.com;

    location / {
        proxy_pass http://localhost:8123;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        # Enables WS support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_redirect off;
    }
}
3 Likes

Thanks Norik, Just have one question dose the Dataplicity URL changes after few hours or it’s a permanent URL !

I was using Remot3 It Custom TCP for accessing my HA from Internet but their URL expires in every 8 hours.

No it doesn’t and for me everything is working fine.

1 Like

the server_name is my dataplicity Wormhole link ?

Yup, That’s correct.

Hi!

Thank you for your help… I’m connecting to HA from the proxy of my Company (with only open the port 80) without any problem.

Now, I’d like to access to my Grafana (and/or the HA Configurator) running in the same RPi3 but through different ports.

Any idea? How to?

Hi @Pharizna did you able to access both through 2 different ports ?

Hi All

Any suggestion how to do so ?
Basically i want to access my home assistant MQTT server through the URL. Currently i have forworded my home assistant 8123 port to port 80 of nginx ane able to access through a URL.

Hi

I spoke with Dataplicity people that confirmed me that’s NOT possible :frowning:

Hi Everybody,

I wonder if I’m the only one who’s suffering from the new auth? Nginx and Dataplicity integration no more works for me.

It works for me. The only thing I’m using Traefik instead of nginx

hi @Norik_Krasniqi ! Awesome hint, I spent half day struggling with NGINX reverse proxy. I was actually trying to do this with port 443.

Since dataplicity website is https I thought I need 443? How is this working through port 80?

I don’t use this solution anymore. I have moved to HA Cloud since. So I am not sure if I can help on this topic right now…

Check my custom component. You don’t need nginx for work

Even though I am using Nabu Casa, I tried your component and is working as it should. Thanks for sharing this solution with us.

Hi. Does it work only on raspberry pi ?
I have HA alpine os running on VM on a macbook and when I add the install command to the integration , it says Error during device registration.
How to proceed ?