【发布时间】:2023-03-16 09:26:01
【问题描述】:
我正在尝试在纯 PHP 页面中显示 Grafana 仪表板。我按照网站说明使用 oauth 进行身份验证。这是我的代码:
<?php
$ch = curl_init();
$authorization = "Authorization: Bearer <myToken>";
curl_setopt_array(
$ch, array(
CURLOPT_URL => 'url-to-my-dashboard',
CURLOPT_HTTPHEADER => array('Content-Type: application/json' , $authorization),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPAUTH => "HTTP/1.1"
));
$output = curl_exec($ch);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php echo $output; ?>
</body>
</html>
页面加载,我得到了 CSS...但我最终遇到了 404 错误。我发现 Grafana 的标头不允许这种操作:
Access to Font at 'http://xxxxx' from origin 'http://localhost'
has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost' is therefore not allowed access.
我很确定我需要配置这些标头:
Header set Access-Control-Allow-Origin "xxx"
Header set Access-Control-Allow-Methods "GET, OPTIONS"
Header set Access-Control-Allow-Headers "origin, authorization, accept"
问题是我不知道我应该在哪里做。我一直在寻找 Grafana(或我们使用的 Graphite)的 .htaccess 文件。我也尝试过修改 Apache2 conf 文件(/etc/apache2/apache2/conf);重启后,没有任何变化...
我很困惑。谁能帮帮我?
【问题讨论】:
-
您的问题解决了吗?通过@JMeterDude
标签: php apache http-headers graphite grafana