1、申请SSL证书

申请好域名证书,将证书文件上传至服务器

  1. mkdir /usr/local/monitor/grafana-8.0.3/ssl
  2. 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

  1. ......
  2. #################################### Server ##############################
  3. [server]
  4. # Protocol (http, https, h2, socket)
  5. protocol = https #修改为https
  6. # The ip address to bind to, empty will bind to all interfaces
  7. http_addr =
  8. # The http port to use
  9. http_port = 3000
  10. # The public facing domain name used to access grafana from a browser
  11. domain = prometheus.123.top #添加要使用的域名
  12. # Redirect to correct domain if host header does not match domain
  13. # Prevents DNS rebinding attacks
  14. enforce_domain = false
  15. # The full public facing url
  16. root_url = %(protocol)s://%(domain)s:%(http_port)s/
  17. # Serve Grafana from subpath specified in `root_url` setting. By default it is set to `false` for compatibility reasons.
  18. serve_from_sub_path = false
  19. # Log web requests
  20. router_logging = false
  21. # the path relative working path
  22. static_root_path = public
  23. # enable gzip
  24. enable_gzip = false
  25. # https certs & key file
  26. cert_file =/usr/local/monitor/grafana-8.0.3/ssl/full_chain.pem #添加证书
  27. cert_key =/usr/local/monitor/grafana-8.0.3/ssl/private.key #添加证书
  28. ......

3、测试访问

  1. curl -I https://prometheus.123.top:3000
  2. HTTP/1.1 302 Found
  3. Cache-Control: no-cache
  4. Content-Type: text/html; charset=utf-8
  5. Expires: -1
  6. Location: /login
  7. Pragma: no-cache
  8. Set-Cookie: redirect_to=%2F; Path=/; HttpOnly; SameSite=Lax
  9. X-Content-Type-Options: nosniff
  10. X-Frame-Options: deny
  11. X-Xss-Protection: 1; mode=block
  12. Date: Mon, 21 Jun 2021 09:35:06 GMT

image.png