Skip to content

Instantly share code, notes, and snippets.

@bwze
Last active February 22, 2019 17:43
Show Gist options
  • Save bwze/aac9cf857c8d05a30f61a51ed4d50b59 to your computer and use it in GitHub Desktop.
Save bwze/aac9cf857c8d05a30f61a51ed4d50b59 to your computer and use it in GitHub Desktop.

NGINX Subfolder Setup

This document will attempt to assit with helping you to understand how to create a subfolder that you can access via a panel iframe component. Using this method, you should be able to access Hass.io addons from outside of your home network.

I will assume you already have the NGINX addon up and running on HASSOS.

I will use Node-RED as the target URL for this example....so I will also assume you have that addon installed and running too.

Understanding the process

First and foremost, I make no claims to be an expert when it comes to NGINX configuration. I just consider myself lucky with actually getting this to work and feel I have a basic understanding of what's going on behind the scenes to explain it in my own way.

NGINX uses a file (nginx_proxy_default.conf) to redirect specific inbound traffic from port 443 to a URL of your choosing that exists on your local network.

Create a default NGINX config file

Using a text editor, create a file with the following structure, ensuring you enter the proper IP address for your instance of Node-RED. This should be your Home Assistant IP address with port 1880 appended. Save this file as nginx_proxy_default.conf in your /share/ folder.

location /nodered/ {
    rewrite /nodered/(.*) /$1 break;
    proxy_pass http://your_local_home_assistant_IP_address:1880;

    proxy_redirect http:// https://;
    proxy_http_version 1.1;
    proxy_set_header Host $host; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
}

Head over to the NGINX addon via the Hass.io tab and scroll down to the Config section. Change active to true...

{
  "domain": "your_domain_name",
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem",
  "hsts": "max-age=31536000; includeSubDomains",
  "customize": {
    "active": true,
    "default": "nginx_proxy_default*.conf",
    "servers": "nginx_proxy/*.conf"
  }
}

Ensure that you restart the addon after making this change to your config...

Change Node-RED config for non SSL connection

Visit the Node-RED addon config and change "ssl" and "require_ssl" to false since from now on NGINX will be handling the SSL piece for you...

{
  "log_level": "info",
  "credential_secret": "you_can't_have_my_super_secret_password",
  "dark_mode": false,
  "http_node": {
    "username": "",
    "password": ""
  },
  "http_static": {
    "username": "",
    "password": ""
  },
  "port": 1880,
  "ssl": true,
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem",
  "require_ssl": true,
  "system_packages": [],
  "npm_packages": [],
  "init_commands": []
}

Add the panel iframe component to your configuration.yaml

Use the following as an example...

panel_iframe:
  node_red:
    title: 'Node-RED'
    url: 'https://**your_doman_name**/nodered'
    ```
When done, check your config to make sure it's correct and then restart Home Assistant.

Next, browse to your Home Assistant domain name and you should have a new panel on the left titled "Node-RED", assuming you used the name from my example...

Give it a click and see if takes you to your Node-Red instance. You should see it render with a prompt for your username and password.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment