anryko / grafana-influx-dashboard

Grafana InfluxDB scripted dashboard
MIT License
132 stars 44 forks source link

Fails if used behind a reverse proxy with a sub path #80

Open jshumaker opened 6 years ago

jshumaker commented 6 years ago

If Grafana is behind a reverse proxy with a subpath, then getdash.js fails as it eventually starts querying without the subpath. In window.grafanaBootData I can see it has the sub-path in most locations, but not for the settings.datasources.*.url which all start with /api/

anryko commented 6 years ago

Thanks for reporting. I'll try to fix it during upcoming weekend.

jshumaker commented 6 years ago

Thanks, I'm fairly new to Grafana, but might see if I can figure out a fix on Friday.

anryko commented 6 years ago

@jshumaker I suspect that the issue might be in this function: https://github.com/anryko/grafana-influx-dashboard/blob/master/getdash.app.js#L721-L771. This is the only place where urls are constructed. If you would like to fix it, that would be the place to start debugging.

Zeuh commented 5 years ago

For apache with mod_proxy and mod_proxy_html :

    ProxyPreserveHost On
    ProxyPass /subpath/metrics/ http://grafana-backend.example.com:3000/
    ProxyHTMLURLMap http://grafana-backend.example.com:3000/ /subpath/metrics/

    <Location /subpath/metrics/api>

        Header Set Pragma "no-cache"
        Header Set Expires "Thu, 1 Jan 1970 00:00:00 GMT"
        Header Set Cache-Control "max-age=0, no-store, no-cache, must-revalidate"
        Header Unset ETag
        FileETag None

        ProxyPassReverse http://grafana-backend.example.com:3000/api
        ProxyHTMLURLMap  http://grafana-backend.example.com:3000/api  /subpath/metrics/api
        RequestHeader    unset  Accept-Encoding
        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1

    </Location>

    <Location /subpath/metrics>
        ProxyPassReverse http://grafana-backend.example.com:3000
        ProxyHTMLURLMap  http://grafana-backend.example.com:3000  /subpath/metrics
        RequestHeader    unset  Accept-Encoding
        SetEnv force-proxy-request-1.0 1
        SetEnv proxy-nokeepalive 1
    </Location>