Grafana(版本 9)在domainA 上运行,无需代理。我想从另一个域 B 添加 Nginx 代理。
根据这个post ,Grafana不支持多个域,需要智能代理。
基于on official documentation , this first post和 this second post ,Nginx 配置应该如下所示
# this is required to proxy Grafana Live WebSocket connections.
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream grafana {
server domainA;
}
server {
listen 8080;
server_name domainB;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host domainA;
proxy_pass https://grafana-prj-sso-monitoring.apps.okd.svc.elca.ch;
}
# Proxy Grafana Live WebSocket connections.
location /api/live/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host domainA;
proxy_pass https://domainA;
}
}
我可以通过代理访问 Grafana,但面板返回“不允许来源”。我尝试在两个位置添加标准 CORS header ,但没有成功
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST';
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type';
add_header 'Access-Control-Allow-Credentials' 'true';
最佳答案
最后这适用于单个位置
location / {
proxy_set_header Host domainA;
proxy_set_header Origin https://domainA;
proxy_pass https://domainA;
}
诀窍是更改 Host 和 Origin header 。
关于nginx - 来自不同域的 Nginx 后面的 Grafana 在面板上返回 "Origin not allowed",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74927448/