nginx代理grafana实现javascript调用 HTTP API

402 阅读1分钟

nginx代理grafana实现javascript调用 HTTP API

Nginx 配置

        location / {
           root   html;
           index  index.html index.htm;
           proxy_pass http://localhost:8080/;
       }

       location /grafana/ {
           root   html;
           index  index.html index.htm;            
           proxy_pass http://localhost:3000/;
           rewrite ^/grafana/(.*) /$1 break;
           proxy_set_header   Host $host;
       }

localhost:8080 为前端服务

localhost:3000 为granfan服务 

统一代理到localhost下。

配置Grafana 在grafana.ini (window上是defaults.ini)文件中 修改为

root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/

js调用 

axios
  .request({
    url: "http://localhost/grafana/api/search",
    method: "get",
    headers: {
      Accept: "application/json",
      "Content-Type": "application/json",
      Authorization:
        "Bearer eyJrIjoiZ1BkdjFuVWhpVFJYVDFnNlI4aWVkNjloM3hGSDRUbXkiLCJuIjoidGVzdCIsImlkIjoxfQ=="
    },
    params: { folderIds: 0, starred: false }
  })
  .then(res => {
    console.log(res);
  });

结果