我想使用dashboard
作为我的grafana安装的nginx位置。
问题是grafana在其中一些url中使用了仪表板,比如https://example.com/grafana/dashboard/new?orgId=1
,我希望它是https://example.com/dashboard/dashboard/new?orgId=1
,我认为我的nginx位置正在重写为https://example.com/dashboard/new?orgId=1
。
当我将它设置为使用grafana
作为子路径时,它就可以正常工作了;
grafana.ini:
[server]
http_addr = 127.0.0.1
domain = example.com
root_url = %(protocol)s://%(domain)s/grafana/
nginx配置:
# Upstream Servers
upstream grafana_server {
server localhost:3000;
}
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
root /var/www/example.com/html;
index index.html index.htm;
server_name example.com www.example.com;
location /grafana/ {
proxy_pass http://grafana_server/;
proxy_set_header Host $host;
}
}
但是将其更改为dashboard
并导航到https://example.com/dashboard/dashboard/new?orgId=1
会导致url被重写为https://example.com/dashboard/new?orgId=1
grafana.ini:
[server]
http_addr = 127.0.0.1
domain = example.com
root_url = %(protocol)s://%(domain)s/dashboard/
nginx配置:
# Upstream Servers
upstream grafana_server {
server localhost:3000;
}
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
include snippets/ssl-example.com.conf;
include snippets/ssl-params.conf;
root /var/www/example.com/html;
index index.html index.htm;
server_name example.com www.example.com;
location /dashboard/ {
proxy_pass http://grafana_server/;
proxy_set_header Host $host;
}
}
所以我试着在nginx位置做了一个重写,但是不能让它按要求工作(真的不知道该怎么做)
location ~ (\/dashboard\/) {
proxy_pass http://grafana_server$1;
proxy_set_header Host $host;
}
location ~ /dashboard/ {
rewrite ^ /dashboard/$1;
proxy_pass http://grafana_server;
proxy_set_header Host $host;
}
任何帮助都将不胜感激。
致以敬意,
发布于 2019-04-03 20:38:28
我知道这有点晚了--但我偶然发现了同样的问题,我想我应该分享一下,以防其他人点击这个帖子:
这不是nginx的问题,而是grafana本身的问题。
我无法用其他方法解决这个问题,只能将root_url
的最后一部分重命名为不同于/dashboard
的名称
https://stackoverflow.com/questions/53973457
复制相似问题