Implementation reverse Proxy
Closed this issue · 26 comments
Hi Dattel,
first of all thanks for the addon. Hopefully this one stays active!
I just miss one thing: the reverse proxy that the UI is accessible throug the home assistant webinterface.
Would be cool if you could add this.
Thanks!
Hi @smoki3,
i'll try to update the addon as long as possible :-D
If there will be any official influxdb2 addon, my plugin will become stale...
You mean the ability to add the InfluxDB2 Interface to the Homeassistant Sitebar?
That is currently not supported... for HA-Addons it is called ingress support. As i know, no other influxdb2-addon is able to provide ingress support. if you have any additional documentations on that, let me know..
Yes this is exatly what I mean.
So may we could implement this. Looking actual at the documentation
so I am trying to get it fixed:
https://github.com/smoki3/homeassistant-influxdb2
If found some reports on google that influxv2 is working with nginx but cant get it to work until now
I already tried to make it work the same fashioned way other addons are using ingress without success (similar to your implementation)... so i decided to leave it out of my addon till i find a working solution....
but would be great, if we can make it work
So up to now nginx is running but the screen stays grey
as i remember, thats the same point where i stopped
Looks promising at the end... will try it out in the next couple of days... if you are faster, please let me know :-D
would be cool if you can have a look on this!
My skills are not good enough for this
Können wir auch auf Deutsch machen :-D
Ich hab's mir gestern mal kurz angeschaut und du hast ja im Prinzip die LUA und NGINX Implementierung von dem offiziellen CommunityPlugin der Influx1 adaptiert. Das war auch damals mein Ansatz. Ich bin aber gestern nicht über eine ERROR 503 hinausgekommen, da schon das cont-init.d Script nicht so funktioniert hat, wie es sollte..
also ich hab es jetzt einmal mit den nginx von dem v1 influx addon probiert und noch einmal von dem offziellen grafana addon da das auch schon s6 nutzt.
Beim dem nginx von v1influx:
bekomm ich ein complett grauen screen. das mit dem cont-init.d hatte ich auch, das war ein permission problem das ich über das Dockerfile lösen konnte. Dannach kam dann kein Fehler mehr sondern was war komplett grau.
Mit dem test von grafana:
bekomme ich 502 bad gateway
ja selbiges bei mir, aber das ist aktuell kein Permission Problem mehr sondern ein Inhaltliches.
das cont-init.d Script wird zwar ausgeführt, aber nicht korrekt.. Ich hab mir da ein paar Debug-Ausgaben eingebaut und festgestellt, dass der Code innerhalb der "if bashio::var.has_value "${port}"; then" Abfrage nicht ausgeführt wird - somit gibt es am Ende keine gültige nginx.conf. Ich weiß leider noch nicht, wo der Parameter "port=$(bashio::addon.port 80)" her kommen soll- da fehlte mir gestern die Motivation.
Selbiges wurde auch durch meine Shell direkt im Docker bestätigt, dass es im Verzeichniss /etc/nginx/servers zur Laufzeit keine aktive .Conf gibt.
Aber schlussendlich denke ich, wird das zum Laufen bringen des NGINX am Ende das kleinere Problem sein.
Update: ach ich weiß, wir der Parameter herkommt.
config.yaml
ports:
80/tcp: null
8086/tcp: 8086
ports_description:
80/tcp: Web interface (Not required for Ingress)
8086/tcp: InfluxDB server
ja genau den habe ich drin
Stück für Stück....
- also die Konfiguration für den Port 80 kannst du einfach ignorieren - den brauchst du nur, wenn du das ganze NGINX-Geraffel noch anderweitig aus dem Docker exposen möchtest. Da das Plugin ja direkt schon das Influx Frontent unter einem anpassbaren Port 8086 (oder deinem Custom Port) anbietet, sehe ich das erstmal als irrelevant an, da nochmal was vorzuschnallen (später dann für automatische Anmeldung ggf)...
- also könnte aus der nginx.sh der ganze "IF" Teil rausfliegen... und die direct.conf sowie direct-ssl.conf können wir erstmal ignorieren.
- relevant wird dann tatsächlich erstmal nur der Inhalt von /etc/ngins/servers/ingress.conf
den hab ich aktuell wie folgt zum Testen abgewandelt:
server {
listen %%interface%%:%%port%% default_server;
include /etc/nginx/includes/server_params.conf;
include /etc/nginx/includes/proxy_params.conf;
access_log /proc/1/fd/1;
location / {
allow 172.30.32.2;
deny all;
root /etc/nginx/test;
index index.html index.htm;
#proxy_pass http://backend%%ingress_entry%%/;
}
}
- Zum Einen siehst du jetzt im Log des Addons die Requests und zum Anderen solltest du damit in der Lage sein, static files anzeigen zu können (rein erstmal zum Verständnis, wie das ganze funktionieren soll)-> lege dazu einfach ein statisches file mit beliebigem Inhalt zum Testen an /etc/nginx/test/index.html
- Als nächstes dann den Proxy testen... Beim Starten des Dockers wird in der ingress.conf die Ersetzung der Var's gemacht - > am Ende steht dann da sowas ähnliches drin
proxy_pass http://backend/api/hassio_ingress/S8X_rhF3kptEiAvCFH8A6SqXicRvacCUiRePhgOD8VE/;
- damit schauen wir dann in der upstream.conf nach -> da steht dann, dass "backend" an die 127.0.0.1:8086 weitergereicht werden sollte... das ist ja genau das, was wir wollen.... im Docker läuft die DB unter 8086 - sollte also alles fein sein
... erstmal Pause hier für mich ...
soweit verstanden glaub ich :-)
das bekomme ich in der log:
172.30.32.2 - - [15/Feb/2024:14:53:31 +0100] "GET / HTTP/1.1" 200 355 "https://XXXXXXXXXXXXXXX/hassio/addon/16663c78_influxdb2in/info" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
Ohhh das sieht sehr gut aus 👌
hm... jetzt hab ich das Update bereitgestellt, aber komme grade nicht ran auf meinem LIVE System
hab's grade nochmal rausgenommen, bis ich weiß, warum es hier nicht läuft
... aktuell nur im "ingress"-Tree..
Ich kämpfe hier grade etwas mit dem Repository
wenn ich weiß, warum es bei mir nicht läuft, dann schalte ich es im nächsten Release wieder frei
Was aktuell nicht funktioniert, ist das automatische Einloggen und ich hab auch das ganze LUA Geraffel erstmal rausgelassen. Damit könnte man das Fontend nochmal gekapselt über den NGINX-Proxy anbieten. Ich sehe da aber keinen Vorteil, da der automatische Login mit den HA-Credentials grade sowieso nicht funktioniert.
Wenn du einen Grund hast, warum wir das benötigen, dann lass es mich wissen, sonst nehme ich den Teil des Codes irgendwann mal raus.
super arbeit! ich hab zwar noch nicht verstanden warum meine verusche gescheitert sind aber hauptsache du warst erfolgreich.
Finde das mit dem Login so wie es ist auch gar kein Problem.
Der Trick liegt einzig in der ingress.conf. Hier werden Pfade verbogen.
Dieses gesamte rewrite/sub_filter Geraffel korrigiert sozusagen, dass InfluxDB2 eigentlich nicht dafür vorgesehen ist, hinter einem Proxy zu laufen.
Über Ingress muss eine APP quasi über ein Subdirectory erreichbar sein.
Beispielsweise bekommt der NGINX im Container dann einen Request in der Form:
http://192.168.1.1:8123/api/hassio_ingress/A3e21rDsxYAkd0CWVEd1arbXV_flbfKw6YBB-gdGkpk/api/v2/query?orgID=xxxxxxx
Jetzt weiß NGINX "AHA, ich muss jetzt also http://localhost:8086/api/v2/query?orgID=xxxxxxx
zurück liefern, weil ich ja nur der Proxy bin."
Unter der Adresse antworte jetzt der Influx2 Server und liefert seinerseits Code an den NGINX zurück als Response - Influx weiß aber nichts davon, dass es hinter http://192.168.1.1:8123/api/hassio_ingress/A3e21rDsxYAkd0CWVEd1arbXV_flbfKw6YBB-gdGkpk
versteckt wird und liefert in seinem ausgeliefertem Response falsche relative Pfade aus. Das kannste entweder umgehen, indem du Influx2 selber kompilierst oder halt über solch einen Hack..
Früher InfluxDB1 hatte kein eigenes Frontend sondern hat Chronograf mitgebracht. Diesem Frontend konnte man beim Starten seinen BasePath mitgeben.
Ich hab aber auch ne Weile gebraucht um das zu verstehen :-D