There are lots of posts in the forum about difficulties displaying grafana charts in sitemaps, when openHAB is being run through a nginx reverse proxy. A number of possible solutions are discussed but, unless I am missing something, none were very easy or straightforward.
This seems to be the easiest way.
- add an nginx location block to catch public urls starting ‘grafana’. The below example shows my standard openahb location block followed by the new grafana block:
location / {
proxy_pass http://localhost:8080/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto "https";
auth_basic "Unauthorised access prohibited";
auth_basic_user_file /etc/nginx/.htpasswd;
}
location /grafana/ {
proxy_pass http://localhost:3001/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto "https";
auth_basic "Unauthorised access prohibited";
auth_basic_user_file /etc/nginx/.htpasswd;
}
I have openHAB running on port 8080 and grafana on port 3001, both on the same PC as nginx.
- Then when grafana generates a url like this:
http://localhost:3001/render/d-solo/XTnqdJOmz/climate-control?panelId=15&orgId=1&from=now-31d&to=now&width=380&height=190
I can display it in the sitemap as simply as:
Webview height=6 url="/grafana/render/d-solo/XTnqdJOmz/climate-control?panelId=15&orgId=1&from=now-31d&to=now&width=380&height=190"
Important that in the grafana.ini file, root_url is not set (despite the instructions) and anonymous access is permitted.