Grafana behind Nginx and Apache Proxy


(: May 17, 2018)

In this guide, I’ll show you how to deploy Grafana behind Nginx and Apache web server to proxy all access requests. This configuration assumes you have a ready Grafana installation, refer to our guide on how to Install Grafana and InfluxDB on CentOS 7.

Grafana behind Nginx

If you are using Nginx as your web server, the configuration will differ from one for Apache. Create nginx configuration file with content like below.

server {
  listen 80;
  root /usr/share/nginx/www;
  index index.html index.htm;
location / {
        proxy_pass http://localhost:3000;
	proxy_set_header    Host             $host;
        proxy_set_header    X-Real-IP        $remote_addr;
        proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;

}{text-align:left} img{margin:0 auto 0 0}

If you have ssl enabled, add:

listen 443 ssl; 
    ssl_certificate /certpath
    ssl_certificate_key  /certkeypath

Confirm configuration syntax and restart nginx

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# service nginx restart

Grafana behind Apache

In case you are running an Apache web server,  you can add a VirtualHost with a configuration similar to below:

<VirtualHost *:80>

DocumentRoot /var/www/html/
ServerAdmin [email protected]
   ProxyPreserveHost On
   ProxyPass / http://localhost:3000/
   ProxyPassReverse / http://localhost:3000/
   ErrorLog logs/grafana_error_log
   TransferLog logs/grafana_access_log

Confirm that configuration is fine and restart apache server:

# apachectl -t
Syntax OK

You should be able to access Grafana dashboard using your server hostname.{text-align:left} img{margin:0 auto 0 0}

Comments are closed, but trackbacks and pingbacks are open.