使用nginx反向代理访问grafana服务
本例测试用的域名(假的):? ? ? ? ? ? ? ? ? x179.com
本例原本能正常访问的grafana地址:? ?192.168.10.90:3000
准备用nginx反代grafana后的地址:?? ? ?http://x179.com/grafana/
vim /etc/grafana/grafana.ini
● 修改 [server] 区域
? ?○ 修改?;domain = localhost? 改为 domain = x179.com
? ?○ 修改 ;root_url = 处为 root_url = %(protocol)s://%(domain)s/grafana/
? ?○ 修改 ;serve_from_sub_path = true 为?serve_from_sub_path = false
● 修改 [auth.proxy] 区域
[auth.proxy]
enabled = true
header_name = X-WEBAUTH-USER
header_property = username
auto_sign_up = true
;sync_ttl = 60
whitelist =
;headers = Email:X-User-Email, Name:X-User-Name
# 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
注意:该启用的启用。完全可以照抄上面一段
systemctl restart grafana-server
注意:可能此时你在用ip地址形式访问grafana应该不行了。等配置完nginx反代后再用域名访问。
[root@meta79 conf.d]# cat /etc/nginx/conf.d/default.conf
upstream grafana {
# 这里写你原来访问grafana的完整地址
server 192.168.10.90:3000;
}
server {
listen 80;
# 这里写你改用域名的形式的访问grafana的域名
server_name x179.com www.x179.com;
access_log /data/ningx/logs/grafana.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# 这里配反代
location /grafana/ {
proxy_pass http://grafana;
proxy_redirect default;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
nginx -t && nginx -s reload
(别忘记修改你主机的hosts指向)