1、申请SSL证书
申请好域名证书,将证书文件上传至服务器
mkdir /usr/local/monitor/grafana-8.0.3/ssl
scp rules.tar.gz root@d-prometheus:/usr/local/monitor/grafana-8.0.3/ssl
2、修改grafana配置文件
$ vim /usr/local/monitor/grafana-8.0.3/conf/defaults.ini
......
#################################### Server ##############################
[server]
# Protocol (http, https, h2, socket)
protocol = https #修改为https
# The ip address to bind to, empty will bind to all interfaces
http_addr =
# The http port to use
http_port = 3000
# The public facing domain name used to access grafana from a browser
domain = prometheus.123.top #添加要使用的域名
# Redirect to correct domain if host header does not match domain
# Prevents DNS rebinding attacks
enforce_domain = false
# The full public facing url
root_url = %(protocol)s://%(domain)s:%(http_port)s/
# Serve Grafana from subpath specified in `root_url` setting. By default it is set to `false` for compatibility reasons.
serve_from_sub_path = false
# Log web requests
router_logging = false
# the path relative working path
static_root_path = public
# enable gzip
enable_gzip = false
# https certs & key file
cert_file =/usr/local/monitor/grafana-8.0.3/ssl/full_chain.pem #添加证书
cert_key =/usr/local/monitor/grafana-8.0.3/ssl/private.key #添加证书
......
3、测试访问
curl -I https://prometheus.123.top:3000
HTTP/1.1 302 Found
Cache-Control: no-cache
Content-Type: text/html; charset=utf-8
Expires: -1
Location: /login
Pragma: no-cache
Set-Cookie: redirect_to=%2F; Path=/; HttpOnly; SameSite=Lax
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-Xss-Protection: 1; mode=block
Date: Mon, 21 Jun 2021 09:35:06 GMT