【发布时间】:2021-01-24 04:06:41
【问题描述】:
我已按照 Grafana (https://grafana.com/tutorials/run-grafana-behind-a-proxy/#1) 提供的说明进行操作,但仍然没有成功。下面是我的 nginx 配置文件。问题是当我转到 http://www.example.com/grafana 时,它会将我重定向到返回 404 的 www.example.com/login。感谢您的帮助!
NGINX 配置文件
server {
listen 80;
listen [::]:80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# Portainer
location /portainer/ {
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://www.example.com:9000/;
}
location /portainer/ws/ {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_pass http://www.example.com:9000/ws/;
}
# Grafana
location /grafana/ {
proxy_pass http://www.example.com:3000/;
}
}
Grafana 配置文件
#################################### Server ####################################
[server]
# Protocol (http, https, h2, socket)
;protocol = http
# The ip address to bind to, empty will bind to all interfaces
;http_addr =
# The http port to use
;http_port = 3000
# The public facing domain name used to access grafana from a browser
;domain = example.com
# Redirect to correct domain if host header does not match domain
# Prevents DNS rebinding attacks
;enforce_domain = false
# 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/grafana/
# Serve Grafana from subpath specified in `root_url` setting. By default it is set to `false` for compatibility reasons.
;serve_from_sub_path = true
# Log web requests
;router_logging = false
# the path relative working path
;static_root_path = public
# enable gzip
;enable_gzip = false
# https certs key file
;cert_file =
;cert_key =
# Unix socket path
;socket =
【问题讨论】:
-
看来问题出在 grafana 方面。查看grafana的访问日志和“curl -v http://www.example.com:3000/”的输出
-
对不起,我试图弄清楚如何访问“访问日志”,但找不到任何东西。在 Portainer 中,当我尝试访问 grafana 时,它会输出这个。
t=2020-10-11T19:50:38+0000 lvl=info msg="Request Completed" logger=context userId=0 orgId=0 uname= method=GET path=/grafana/ status=302 remote_addr=172.17.0.1 time_ms=0 size=29 referer= -
你能在 3000 端口上 curl 服务器吗?如果是这样,grafana 正在运行,我们可以只关注 nginx 问题。要测试,请尝试运行: curl -sS localhost:3000/login 这应该会返回一大段文本(通常会在浏览器中呈现登录屏幕) – user2863294 11 分钟前
标签: nginx grafana nginx-reverse-proxy