nginx代理访问grafana分为两步:
- 配置nginx
vim /usr/local/nginx/conf/nginx.conf
修改如下:
server {
listen 80;
root /usr/share/nginx/www;
index index.html index.htm;
//加入
location /PaaS/grafana/ {
proxy_pass http://localhost:3000/; #注意3000后面的斜杠“/”不要漏掉
proxy_set_header Host $host;
}
}
保存,重载nginx
cd /usr/local/nginx/sbin
./nginx -s reload
- 配置grafana
vim /etc/grafana/grafana.ini
修改如下:
[server]
domain = http://eip.ht.com.cn
root_url = %(protocol)s://%(domain)s/PaaS/grafana/
保存,重启grafana
service grafana-server restart
访问:http://eip.ht.com.cn/PaaS/grafana/?orgId=1
注:如果nginx的配置中proxy_pass http://localhost:3000/;
后面不加斜杠,就会出现下面的情况:
image.png
If you're seeing this Grafana has failed to load its application files
This could be caused by your reverse proxy settings.
If you host grafana under subpath make sure your grafana.ini root_url setting includes subpath
If you have a local dev build make sure you build frontend using: yarn start, yarn start:hot, or yarn build
Sometimes restarting grafana-server can help