官方文档地址:
https://grafana.com/tutorials/run-grafana-behind-a-proxy/
一级路径的配置方式
只需要修改Nginx配置文件,主要是增加对WebSocket的支持及反向代理的配置
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
location / {
proxy_pass http://localhost:3000/;
}
location /api/live {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $http_host;
proxy_pass http://localhost:3000/;
}
}
重新载入nginx配置文件
/usr/local/nginx/sbin/nginx -s reload
二级路径路径的配置方式
除了需要修改nginx配置文件外,还需要修改grafana配置文件
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
location ^~ /grafana/ {
proxy_pass http://localhost:3000/;
}
location ^~ /grafana/api/live {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $http_host;
proxy_pass http://localhost:3000/;
}
}
重新载入nginx配置文件
/usr/local/nginx/sbin/nginx -s reload
修改grafana.ini配置文件
vi /etc/grafana/grafana.ini
root_url = %(protocol)s://%(domAIn)s:%(http_port)s/grafana
serve_from_sub_path = true
重启Grafana服务
systemctl restart grafana-server