Hey Rohit, here’s what I’ve done. You can cross verify the below with your config to find out the bug, since the config you shared is not complete or not formatted. Its difficult to read.
First, I’m assuming you’re running running this in Linux. A complete guide on how to configure this is written here.
I ran my setup in Ubuntu.
So for that I’ll edit the defaults.ini
.
From doc :
If you installed Grafana using the deb
or rpm
packages, then your configuration file is located at /etc/grafana/grafana.ini
and a separate custom.ini
is not used.
Next, I’ve edited the doc for only 3 parameters I’ve shared above.
Here’s my config :
# 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
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
#....other default config lines
Next, lets look at the nginx config file :
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream grafana {
server localhost:3000;
}
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
root /usr/share/nginx/www;
index index.html index.htm;
location /grafana/ {
rewrite ^/grafana/(.*) /$1 break;
proxy_set_header Host $http_host;
proxy_pass http://grafana;
}
#charset koi8-r;
#access_log logs/host.access.log main;
# Proxy Grafana Live WebSocket connections.
location /grafana/api/live/ {
rewrite ^/grafana/(.*) /$1 break;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_pass http://grafana;
}
}
}
I did a diff of your file and my file and :
diff nginx.conf rohit.conf
1,3c1
< events {
< worker_connections 1024;
< }
---
>
8d5
<
56,57d52
< }
< }
Only difference between my file and your file is :
- events section is missing
- Two brackets at the end is missing in your file.
I’m assuming you must be familiar with nginx. Here’s how you can test your nginx file for valid syntax :
nginx -t
Which should give you :
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Once that’s valid, I added my hosts file with below entry :
127.0.0.1 example.com
And I can visit the web now :
Note : if you’re running a Red Hat flavoured system, additional config is needed for reverse proxy.
Documented here : Install on RPM-based Linux | Grafana documentation