Skip to content

Reverse Proxy Grafana with Nginx

Video Lecture

Reverse Proxy Grafana with Nginx Reverse Proxy Grafana with Nginx

Description

Now to add a proxy. I will use Nginx.

The Nginx proxy will also allow us to more easily configure our Grafana servers public address and bind an SSL certificate to it.

It is possible to change the grafana.ini settings to use a specific port number, SSL certificates and HTTP protocol instead, but you will also need to manage file permissions that the Grafana server process will need.

It is more manageable to use a dedicated proxy and especially if your server will be hosting multiple web applications.

Check if Nginx is installed

#
nginx -v

No, then install it with

#
apt install nginx

Now check its version

#
nginx -v

Now check its status

#
service nginx status

Visit http://[your IP address]

You should get the default Nginx web server index.html.

CD to the /etc/nginx/sites-enabled folder

#
cd /etc/nginx/sites-enabled

Create a new Nginx configuration for Grafana

#
nano YOUR-DOMAIN-NAME.conf

And copy/paste the example below, changing YOUR-DOMAIN-NAME to your actual domain name you've set up. Mine was grafana.sbcode.net.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
server {
    listen 80;
    listen [::]:80;
    server_name YOUR-DOMAIN-NAME;

    location / {
        proxy_set_header Host $http_host;
        proxy_pass http://localhost:3000/;
    }

    # Optional : Allow WSS for Explore Live connections.
    location /api/ {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $http_host;
        proxy_pass http://localhost:3000/api/;
    }
}

Press CTRLX then ENTER to save and exit nano.

And then test that the Nginx configuration is still OK.

#
nginx -t

Restart Nginx and check its status.

#
#
sudo service nginx restart
sudo service nginx status

Test it by visiting again

http://YOUR-DOMAIN-NAME

If this doesn't work and you have a firewall setup, check that you have rule to allow port 80 inbound.

Also note, that visiting your IP address directly will still the default Nginx welcome page. If you don't want this to happen, then you can delete its configuration using the command below.

#
rm /etc/nginx/sites-enabled/default

Comments