JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

配置nginx代理grafana实现域名访问

wys521 2024-10-07 16:45:21 精选教程 29 ℃ 0 评论

目的:

通过Nginx服务器对grafana进行代理,实现通过https://域名/grafana在公网进行访问

实践过程:

1、修改Nginx配置(nginx.conf)文件,添加访问grafana的配置,配置时注意proxy_pass后面一定要有符号 /(目的是去掉/grafana/以匹配本身)

vi /usr/local/nginx/conf/nginx.conf
    server {
         listen       443 ssl;
         server_name  example.com;

         ssl_certificate cert/example.com.pem;
         ssl_certificate_key cert/example.com.key;
        
         location / {
            root   html;
            index  index.html index.htm;
        }
         location /grafana/ {
             root html;
             index index.html index.htm;
             proxy_pass http://192.168.31.90:3000;
             proxy_redirect default;
             proxy_max_temp_file_size 0k;
             proxy_connect_timeout 30;
             proxy_send_timeout 60;
             proxy_read_timeout 60;
             proxy_next_upstream error timeout invalid_header http_502;
        }

   }

2、修改grafana服务器的配置文件(grafana.ini),注意需要去掉行前的注释符号 “;
[server]段涉及以下三处需要更改:

[server]
domain = 填写你的域名地址
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
serve_from_sub_path = true

3、reload Nginx并重启grafana服务

/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
systemctl restart grafana-server

4、最后提供下官方文档中关于转发的配置说明:
grafana之proxy转发说明

https://grafana.com/tutorials/run-grafana-behind-a-proxy/#1

转发配置如下:

[server]
domain = example.com
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
serve_from_sub_path = true

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表