您的入口规则是正确的,nginx创建了正确的虚拟主机来转发流量到grafana的服务(我只留下了必要的字符串来显示)。
server {
server_name sample.com;
listen 80;
listen [::]:80;
set $proxy_upstream_name "-";
location ~* ^/grafana/(?<baseuri>.*) {
set $proxy_upstream_name "default-grafana-grafana-80";
set $namespace "default";
set $ingress_name "grafana-ingress-v1";
rewrite /grafana/(.*) /$1 break;
rewrite /grafana/ / break;
proxy_pass http://default-grafana-grafana-80;
}
是的,当您访问 sample.com/grafana/
时,您将收到来自grafana pod的响应,但它会重定向到 sample.com/login
页面(从您提供的屏幕截图可以看到):
$ curl -v -L http://sample.com/grafana/
* Trying 192.168.99.100...
* Connected to sample.com (192.168.99.100) port 80 (
> GET /grafana/ HTTP/1.1
> Host: sample.com
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 302 Found
< Server: nginx/1.13.5
< Date: Tue, 30 Jan 2018 21:55:21 GMT
< Content-Type: text/html
< Content-Length: 29
< Connection: keep-alive
< Location: /login
< Set-Cookie: grafana_sess=c07ab2399d82fef4
< Set-Cookie: redirect_to=%252F
<
* Ignoring the response-body
* Connection
* Issue another request to this URL: 'http://sample.com/login'
* Found bundle for host sample.com: 0x563ff9bf7f20 [can pipeline]
* Re-using existing connection! (
* Connected to sample.com (192.168.99.100) port 80 (
> GET /login HTTP/1.1
> Host: sample.com
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Server: nginx/1.13.5
< Date: Tue, 30 Jan 2018 21:55:21 GMT
< Content-Type: text/plain
< Content-Length: 21
< Connection: keep-alive
<
* Connection
default backend 404
因为默认情况下Grafana的root_url
只是/
:
root_url = %(protocol)s://%(domain)s:%(http_port)s/
当请求重定向到只有sample.com
时,nginx会将其转发到默认的404后端。
解决方案:
您需要更改grafana服务器设置中的root_url
为/grafana/
:
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
您可以通过更改grafana的configmap
对象中的此设置来完成此操作。