狂自私

导航

nginx代理grafana

nginx代理grafana

背景

我自己nginx不怎么会,然后我的生产环境已经不允许我使用【/】这个根路径了。我只能为其加上一个路径来解析。

网络拓扑示意图

如图所示,我想在运维电脑上请求grafana web。但是这中间夹了几层,目前已知防火墙是放通了负载均衡的80端口到运维电脑上,nginx和负载均衡是互通的,nginx和grafana是互通的。

最终目标

我在系统里面访问【http://192.168.25.61/grafana/】可以访问到grafana。

步骤

nginx配置

    server {
        listen 80;
#        server_name 192.168.25.61;  # 这里填写负载均衡服务器的 IP 或域名,但若是只有一个Server就可以不填,多个Server如果不冲突也可以不填

        location /grafana/ {
            rewrite ^/grafana/(.*)$ /$1 break;  # 重写请求路径
            proxy_pass http://192.168.25.5:3000/;  # 这里填写 grafana 服务的地址和端口(默认是 3000 端口)
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }

[root@test ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@test ~]#
[root@test ~]# systemctl restart nginx

 

grafana配置

[root@harbor ~]# vi /etc/grafana/grafana.ini

# The full public facing url you use in browser, used for redirects and emails
# If you use reverse proxy and sub path specify full url (with sub path)
;root_url = %(protocol)s://%(domain)s:%(http_port)s/
# 这里是配合192.168.25.61(test)主机上的NGINX配置做的改动。
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/

[root@harbor ~]# systemctl restart grafana-server

 

然后就行了。

结果

posted on 2024-09-20 12:50  狂自私  阅读(4)  评论(0编辑  收藏  举报