Connecting to External InfluxDB on a Reverse Proxy

Hello,

I want to connect a home assistant to an external InfluxDB that is behind a reverse proxy (Nginx). The InfluxDB is on a rpi that is outside my network but I can access to it through the Nginx reverse proxy. The InfluxDB is installed on the external rpi using the Frenck’s addon and the Nginx is managed with the Nginx Proxy Manager. I created a proxy host that forwards the http://db.XXX.duckdns.org to the rpi IP and port 8086. I did not setup the SSL for the Influx connection for the time being.

The InfluxDB addon config looks like this:

auth: true
reporting: true
ssl: true
certfile: fullchain.pem
keyfile: privkey.pem
envvars:
  - name: INFLUXDB_HTTP_LOG_ENABLED
    value: 'true'

I’ve created the db and the user using the InfluxDB WebUI on the external rpi and I’ve added to the config.yaml the following entry to the local rpi:

influxdb:
  host: db.XXX.duckdns.org
  path: http://db.XXX.duckdns.org
  database: !secret influxdb_db
  username: !secret influxdb_user
  password: !secret influxdb_password
  max_retries: 3
  default_measurement: state

I’ve tried different configuration options but unfortunately none is working. I always get the following error in the log:

Cannot connect to InfluxDB due to 'HTTPConnectionPool(host='db.XXX.duckdns.org', port=8086): Max retries exceeded with url: /http://db.XXX.duckdns.org/write?db=DB_NAME (Caused by ConnectTimeoutError(<urllib3.connection.HTTPConnection object at 0xa8f3d9a0>, 'Connection to db.XXX.duckdns.org timed out. (connect timeout=5)'))'. Please check that the provided connection details (host, port, etc.) are correct and that your InfluxDB server is running and accessible. Retrying in 60 seconds.

Can anyone help me with this? Thanks!

Has anyone every tried to connect to an external InfluxDB around here? Any help would be appreciated!

ok, so I figured out what was the problem. I was not specifying the port of the InfluxDB connection so the connection was trying to be established to the default port 8086. But in reality the Proxy is handling the connection from the http connection to the host (port 80) to the rpi Influx port (8086).

After adding the port 80 to the config it’s working!

Here’s how the config looks like now:

influxdb:
  host: db.XXX.duckdns.org
  port: 80
  database: !secret influxdb_db
  username: !secret influxdb_user
  password: !secret influxdb_password
  max_retries: 3
  default_measurement: state