文章目录
背景
grafana 是通过docker方式部署的,浏览器打开异常
浏览器
Google Chrome 101.0.4951.54 (正式版本) (64 位) (cohort: Stable)
排查思路
http://ip:port直接访问是否正常? 正常的
nginx 路径转发是否有问题?无法打开
报错日志
If you're seeing this Grafana has failed to load its application files
1. This could be caused by your reverse proxy settings.
2. If you host grafana under subpath make sure your grafana.ini root_url setting includes subpath. If not using a reverse proxy make sure to set serve_from_sub_path to true.
3. If you have a local dev build make sure you build frontend using: yarn start, yarn start:hot, or yarn build
4. Sometimes restarting grafana-server can help
5. Check if you are using a non-supported browser. For more information, refer to the list of supported browsers.
查看官网介绍只需要对于这种nginx反向代理需要加上子路径
root_url
This is the full URL used to access Grafana from a web browser. This is important if you use Google or GitHub OAuth authentication (for the callback URL to be correct).
Note: This setting is also important if you have a reverse proxy in front of Grafana that exposes it through a subpath. In that case add the subpath to the end of this URL setting.
nginx 转发地址
# grafana private
location ^~ /zcm-grafana/ {
rewrite ^/zcm-grafana/(.*) /$1 break;
#proxy_set_header 'Authorization' 'Bearer eyJrIjoiMTVCSUtDRFpEVDFpczV6RmVNODMyNVFaNmticHgwVHYiLCJuIjoibXl0ZXN0IiwiaWQiOjF9';
proxy_pass http://172.16.17.82:3000/;
}
解决方式
修改grafana.ini配置
linux默认路径/etc/grafana/grafana.ini
# The full public facing url you use in browser, used for redirects and emails
# If you use reverse proxy and sub path specify full url (with sub path)
;root_url = %(protocol)s://%(domain)s:%(http_port)s/
#修改后(去除首位分号)
# The full public facing url you use in browser, used for redirects and emails
# If you use reverse proxy and sub path specify full url (with sub path)
root_url = %(protocol)s://%(domain)s:%(http_port)s/zcm-grafana/
重启服务可以正常访问,问题解决。