diff --git a/dashboards/dashboard.json b/dashboards/dashboard.json index 9295d6fd..43741c3e 100644 --- a/dashboards/dashboard.json +++ b/dashboards/dashboard.json @@ -1060,7 +1060,7 @@ "id": 13, "links": [], "options": { - "content": "\n
\n \n
\n
\n

Firmware

\n
\n", + "content": "\n
\n \n
\n
\n

Firmware

\n
\n", "mode": "html" }, "pluginVersion": "9.1.2", diff --git a/grafana.env.sample b/grafana.env.sample index 65b3e9b8..5df1e948 100644 --- a/grafana.env.sample +++ b/grafana.env.sample @@ -32,3 +32,8 @@ GF_SECURITY_ALLOW_EMBEDDING=true #GF_SERVER_PROTOCOL=https #GF_SERVER_CERT_FILE=/var/lib/grafana/cert.pem #GF_SERVER_CERT_KEY=/var/lib/grafana/key.pem + +# Serve Grafana from /grafana/ +GF_SERVER_ROOT_URL="%(protocol)s://%(domain)s:%(http_port)s/grafana/" +GF_SERVER_SERVE_FROM_SUB_PATH=true + diff --git a/nginx-host.conf b/nginx-host.conf new file mode 100644 index 00000000..1599408c --- /dev/null +++ b/nginx-host.conf @@ -0,0 +1,64 @@ + + +# this is required to proxy Grafana Live WebSocket connections. +map $http_upgrade $connection_upgrade { + default upgrade; + '' close; +} + +upstream grafana_host { + server grafana:9000; +} + +upstream pypowerwall_host { + server pypowerwall:8675; +} + +server { + listen 80 default_server; + listen [::]:80 default_server; + + root /var/www/html; + server_name _; + + # Proxy /grafana/* & co + location /grafana/api/live/ { + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection $connection_upgrade; + proxy_set_header Host $http_host; + proxy_pass http://grafana_host; + } + location /grafana/ { + proxy_set_header Host $http_host; + proxy_set_header X-Req-URI $request_uri; + proxy_set_header X-Req-Instance "grafana"; + proxy_pass http://grafana_host; + } + + # If location is EXACTLY /, Redirect to /grafana/ + location = / { + absolute_redirect off; + return 301 /grafana/; + } + + # If location is EXACTLY /panel.html, + # this should be rewritten to pypowerwall / + location = /panel.html { + rewrite (.*) / break; + proxy_set_header Host $http_host; + proxy_set_header X-Req-URI $request_uri; + proxy_set_header X-Req-Instance "panel"; + proxy_redirect off; + proxy_pass http://pypowerwall_host; + } + + # Pass any other location to pypowerwall + location / { + proxy_set_header Host $http_host; + proxy_set_header X-Req-URI $request_uri; + proxy_set_header X-Req-Instance "slash"; + proxy_pass http://pypowerwall_host; + } + +} diff --git a/powerwall.yml b/powerwall.yml index 6f49cfd6..c4814c51 100644 --- a/powerwall.yml +++ b/powerwall.yml @@ -96,3 +96,19 @@ services: - WEATHERCONF=/var/lib/weather/weather411.conf depends_on: - influxdb + + nginx: + image: nginx:latest + container_name: nginx + hostname: nginx + restart: always + volumes: + - type: bind + source: ./nginx-host.conf + target: /etc/nginx/conf.d/default.conf + read_only: true + ports: + - target: 80 + published: 8080 + mode: host +