Always Return 404 when using a proxy program to get the grafana view

  • What Grafana version and what operating system are you using?
    Grafana Version is v9.1.0 (82e32447b4), and the os is linux

  • What are you trying to achieve?
    I am trying to implement a proxy-program by Go, which is expected to proxy the

http://113.97.28.220:3002/monitor_grafana/xxxx => http://113.97.28.220:3000/xxxx
  • How are you trying to achieve it?
    Using go-gin library to do that, the implementation are as follows:
func main() {
	r := gin.Default()
	r.Any("/monitor_grafana/*proxyPath", proxy)
	r.Run(":8888")
}

func proxy(c *gin.Context) {
	remote, err := url.Parse("http://113.97.28.220:3000")
	if err != nil {
		panic(err)
	}

	proxy := httputil.NewSingleHostReverseProxy(remote)
	proxy.Director = func(req *http.Request) {
		req.Header = c.Request.Header
		req.Host = remote.Host
		req.URL.Scheme = remote.Scheme
		req.URL.Host = remote.Host
		req.URL.Path = c.Param("proxyPath")
		req.Header.Add("X-WEBAUTH-USER", "admin")
	}

	proxy.ServeHTTP(c.Writer, c.Request)
}

Btw, the configuration of grafana are as follows(only show the relative part):

#################################### Auth Proxy ##########################
[auth.proxy]
enabled = true
header_name = X-WEBAUTH-USER
header_property = username
auto_sign_up = true
sync_ttl = 60
whitelist = 
headers = 
# Non-ASCII strings in header values are encoded using quoted-printable encoding
;headers_encoded = false
# Read the auth proxy docs for details on what the setting below enables
enable_login_token = false

And to fix the CORS issue, I had already use nginx to make following proxy :

http://113.97.28.220:3002/ => http://113.97.28.220:3000/
http://113.97.28.220:3002/monitor_grafana/ => http://113.97.28.220:8888/
ws://113.97.28.220:3002/ => ws://113.97.28.220:3000/
  • What happened?
    When I access to 113.97.28.220:3002/monitor_grafana/d/XSZfs9mVz/d1?orgId=1, it will only return 404 page. And when I check the F12 panel of this page, it shows:

  • What did you expect to happen?
    Normally, to 113.97.28.220:3000/d/XSZfs9mVz/d1?orgId=1, the views will be like:

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    I have set the log to trace level, yet still no log

  • Did you follow any online instructions? If so, what is the URL?
    Nope

Hi @aldrice,

Well, I do not have the expertise in this specific area. All I can suggest is to:

  • Check the logs (var/log/grafana/grafana.log) and see what caused this.
  • Increase the log level to debug mode inside the /etc/grafana/grafana.ini if the current logs do not show any data
  • Link to our documentation about running Grafana behind a Proxy

Also, I found this link which seems like a guide on how to use Grafana with a Go reverse proxy. It is in Russian but Google Translator can do the job :wink:

It seems a good reference guide as how to use it with diagrams and might be helpful.

I hope other community members can help you further to resolve the problem.