Closed zerthimon closed 9 years ago
@zerthimon are you sure you have configured nginx or apache reverse proxy correctly? Are you using version 2.0.2? a lot of poeple have put grafana behind reverse proxy and added sub url to root_url so its strange that no one has reported it before
@torkelo Yep, I'm using grafana 2.0.2
My Nginx is configured this way:
location /grafana/ {
proxy_set_header Host $host;
rewrite ^/grafana/(.*) /$1 break;
proxy_pass http://localhost:3000;
}
And the root_url is:
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
I'm seeing this issue after signing out and logging into grafana. Everything else works fine (i just have to fix the uri in browser from '/' to '/grafana/' after logging in).
Here is the access log (see the "GET /" in the last line):
zzz.zzz.zzz.zzz - graphite [28/May/2015:16:22:28 +0300] "GET /grafana/login HTTP/1.1" 200 997 "https:/xxx.xxx.xxx/grafana/" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0"
zzz.zzz.zzz.zzz - graphite [28/May/2015:16:22:44 +0300] "POST /grafana/login HTTP/1.1" 200 41 "https://xxx.xxx.xxx/grafana/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0"
zzz.zzz.zzz.zzz - graphite [28/May/2015:16:22:44 +0300] "GET / HTTP/1.1" 200 542 "https://xxx.xxx.xxx/grafana/login" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0"
@zerthimon not sure about the rewrite rule, this works for me:
location /grafana2/ { proxy_pass http://localhost:3000 }
@torkelo What do you have in the root_url ? When I have:
location /grafana/ {
proxy_pass http://localhost:3000;
}
I'm getting only this:
{{alert.title}}
and a bunch of 404's in /var/log/grafana/grafana.log
2015/05/28 17:36:03 [I] ESC[1;31mCompleted /grafana/ 404 Not Found in 7.841934msESC[0m
2015/05/28 17:36:03 [I] ESC[1;31mCompleted /grafana/css/grafana.dark.min.5aa0b879.css 404 Not Found in 1.044431msESC[0m
2015/05/28 17:36:03 [I] ESC[1;31mCompleted /grafana/app/app.6e379bdb.js 404 Not Found in 1.025579msESC[0m
2015/05/28 17:36:12 [I] ESC[1;31mCompleted /grafana/ 404 Not Found in 3.022672msESC[0m
2015/05/28 17:36:12 [I] ESC[1;31mCompleted /grafana/app/app.6e379bdb.js 404 Not Found in 3.327384msESC[0m
2015/05/28 17:36:12 [I] ESC[1;31mCompleted /grafana/css/grafana.dark.min.5aa0b879.css 404 Not Found in 3.290403msESC[0m
root url is default value but with granfana/
added to the end
Just tested this and login works fine.
nginx:
location /grafana/ {
proxy_pass http://127.0.0.1:3000/;
grafana ini:
[server]
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana
The trailing slash in http://127.0.0.1:3000/; made it work for me.
But the redirect after login still sends my browser to "/"
strange, must be something wrong with your nginx version?
@zerthimon did you change root_url that ends in grafana/ and did you restart the grafana backend?
@torkelo here is the current config
# The full public facing url
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/
location /grafana/ {
proxy_pass http://localhost:3000/;
}
@torkelo restarted the grafana backend and nginx ... I'm gonna analyze the traffic and report back
Checked with other browsers - no problems found. Cleaned cache and cookies and that solved the problem. Mozilla must have cached the wrong redirect, when I played with configuration.
@torkelo Thanks for assist, grafana is great!
@zerthimon ah, great that you solved it
/etc/init.d/grafana-server restart solved this issue for me
@torkelo I am new to nginx and grafana both. I installed nginx and grafana. Grafana works great with its default settings but when I tried doing the above, unfortunately i then dint get access to grafana, it says {{alert.title}}. And if i revert back the changes, grafana works. Can you please guide me where to write this location directive location /grafana/ { proxy_pass http://localhost:3000/; } inside a new server block in nginx.conf and outside http block? or can you please show me the nginx.conf file. Am i missing something else as well?
@areebahmushtaq
this should work in grafana.ini
root_url = http://your_nginx_and_port/grafana/
Your nginx confiug
location /grafana/ {
proxy_pass http://localhost:3000/;
}
``
for the nginx config, it should go inside a server block
Hi all I have the same problem with the login page. I also have the nginx configuration as recommended:
location /grafana/ {
proxy_pass http://localhost:3000/;
}
And in grafana.ini:
root_url = http://mydomainname/grafana/
I don't see any issue on that configuration so I checked the js of the login page of grafana. After loging the response of the grafana server is
"{"message":"Logged in","redirectUrl":"/"}"
So that "redirectUrl" parameter makes the web browser redirect to the root of my server instead to the location /grafana/
After this, I surf back to the /grafana/ location of the server and I'm logged in due to the session cookie so everything works fine
Did I miss any other configuration parameter that affects this redirectUrl of the response of the login page?
Thanks in advance for your help
The redirectUrl i handled in the frontend and before reloading that page the app sub url is appended. https://github.com/grafana/grafana/blob/master/public/app/core/controllers/login_ctrl.js#L84
or wait, that does not look right. hmm.. might be a bug there
Seems to work for me, you should not get redirectUrl unless you have a redirect cookie (tried accessing a page before logging in and you will get one).
So try clearing any cookies you have
Login works fine but when you try to add datasource the URL is not directed.
The url is not directed? What do you mean?
So I configured the root url and nginx config as in the grafana documentation. And that works fine for login, admin, dashboard, alerting options in grafana. But, when I try to add datasource from UI the page does not show up there and same thing happens for when installing plugins. Following are the latest logs of grafana when I tried to add datasource. Also my nginx config is : location /grafana/ { proxy_pass http://grafana:3000/; ##{I have the services in the same overlay network} LOGS-------- t=2016-12-28T03:09:02+0000 lvl=info msg="Initializing HTTP Server" logger=server address=0.0.0.0:3000 protocol=http subUrl=/grafana t=2016-12-28T03:09:05+0000 lvl=info msg="Request Completed" logger=context userId=0 orgId=0 uname= method=GET path=/datasources status=302 remote_addr=10.0.0.18 time_ms=0s size=37
@karanp24 very strange, cannot replicate and no similar reports :(
@torkelo thanks for the followup. I resolved the issue it was related with nginx. I have /kibana suburl in nginx as well and thats the reason nginx was confused and the kibana urls were getting higher preference. so the updated nginx conf is : location ^~ /grafana/ { proxy_pass http://grafana:3000/;
@torkelo Where you able to do proxy settings in ha proxy? I am using ha proxy instead nginx.
Hi, I have a similar problem with static files:
Nginx conf:
location /grafana {
proxy_pass http://internal_server_ip:3000
}
in grafana.ini
:
root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana
But open in browser will report these 404 errors
(index):11 GET /grafana/public/css/fonts.min.css (index):14 GET /grafana/public/css/grafana.dark.min.c7b017c5.css (index):79 GET /grafana/public/app/boot.85c49108.js
@lambdaq ever make any progress with that - getting the same errors with haproxy
@lambdaq that location settings seems starnge. I would expect it to be /grafana
rather then / grafana
?
@bergquist Sorry It's a typo. It should be /grafana
. I corrected it.
@patrickleet I ended up adding a rewrite
like this:
location /grafana {
rewrite ^/grafana/(.*) /$1 break;
proxy_pass http://internal_server_ip:3000
}
It's working OK.
I've spent more time today fighting this than I'd care to admit. All I can say is that Grafana seems extremely touchy mounted at a subpath. I ended up falling back to proxying Grafana without the subpath; it just wouldn't work.
I think my proxy server (bitly/oauth2_proxy) is forcing a trailing slash, and Grafana refuses to deal with it, but I can't be sure. At a subpath, all I can get is a 404 page that is clearly from Grafana.
@dpetersen strange, never heart of an issue before with putting grafana behind nginx, apache or oauth2 proxy in subpath, that is used by a lot of users.
The assets were not served at the subpath, although the application was, therefore the assets could not be found. Not sure about nginx
but I experienced this in haproxy
. The trick to get it working was to rewrite the subpath to /
Here's relevant config
frontend services
#...
acl url_metrics_grafana3000 path_beg /grafana/ path_beg /grafana/public path_beg /grafana/api
use_backend metrics_grafana-be3000 if url_metrics_grafana3000
backend metrics_grafana-be3000
mode http
http-request set-path %[path,regsub(/grafana/,/)]
server metrics_grafana metrics_grafana:3000
@patrickleet how does your root_url looks like? Also can you go to metrics_grafana:3000 directly?
Update: root_url = %(protocol)s://%(domain)s:%(http_port)s/grafana/ seems to work with @patrickleet haproxy example
I started Grafana as below.
Accessing Grafana via http://server-ip:3000/grafana throws
{{alert.title}} error.
Am I missing anything in the configuration or setup ?
From the log message:
msg="Initializing HTTP Server" logger=server address=0.0.0.0:3000 protocol=http subUrl=/grafana
You specifed http://grafana as root url, so that is what Grafana expects as the url used on browser.
For putting grafana under suburl /grafana you need a reverse proxy like nginx
Thanks for your reply. I tried adding the host behind AWS ALB (path based routing) and added /grafana as the path. But still the same issue exists. Is that anything need to be configured for accessing Grafana using AWS ALB i.e AWS-ALB-Name/grafana throws the above error.
But if I start with default root_url (no sub_urls), I am able to access it via AWS ALB with the corresponding port number i.e. AWS-ALB-Name:3000 works fine.
Not sure how AWS ALB subpath reverse proxy works, I know that it works with apache and nginx.
On Mon, Mar 6, 2017 at 6:26 AM, gsethu notifications@github.com wrote:
Thanks for your reply. I tried adding the host behind AWS ALB (path based routing) and added /grafana as the path. But still the same issue exists. Is that anything need to be configured for accessing Grafana using AWS ALB i.e AWS-ALB-Name/grafana throws the above error.
But if I start with default root_url (no sub_urls), I am able to access it via AWS ALB with the corresponding port number i.e. AWS-ALB-Name:3000 works fine.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/grafana/grafana/issues/2066#issuecomment-284306119, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAq9_biz347EXMFgSQX2BlDzNG_3tnHks5ri5kJgaJpZM4EthQT .
@gsethu @torkelo The ALB path based routing does not do path manipulation so the request Grafana got is http://someip:3000/grafana
. I think there has to be a reverse proxy in the middle to strip out /grafana
because there is no way to configure Grafana to serve a sub path directly.
@dpetersen Sorry for digging up this issue although it is closed. But I am also trying to run grafana behind oauth2_proxy from bitly. Other applications are working quite well like this, but with grafana all I get are 404s. Did you ever got the combination of oauth2_proxy and grafana working?
@dereulenspiegel I only got it working at the root, not at a subpath, and we settled for that. If you're OK with running it at the root and are having problems, shoot me an email at the address in my Github profile, and I can dig up my configs for you.
Deleting everything cached and cookies did the trick.
this configuration,nginx is work。but,direct access will be reported,like this:http://grafana_server:3000/grafana/。return {{alert.title}}。Is it the same?
@aceslup You're still having problems with the paths. But it could be that the problem is on your client side (browser), even when everything works OK on the server side. Make you sure that you're always using a fresh browser profile, or delete cache and cookies.
There are no easy way to run grafana behind AWS ALB. You need to setup nginx + grafana. It would be nice if subUrl is configurable directly within grafana.
Why is this ticket closed ?
I'm running into this issue as well. I'm testing without a load-balancer/proxy set up by running Grafana directly on port 80 as Root (for testing only). I run into the same redirect issue with /login. Not sure how to debug this further. I have taken the suggestions into account from this thread.
I had the same problem. Commenting out the following in my NGINX config resolved the issue.
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
expires 7d;
access_log off;
}
location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff|woff2)$ {
add_header Access-Control-Allow-Origin "*";
expires 7d;
access_log off;
}
It redirects to a '/' instead of what is configured in the 'root_url'