How to Make Your Grafana Dashboard Publicly Accessible with a Domain Name
Story
Have you ever wondered how to turn your local Grafana instance into a publicly accessible dashboard? I wonder how organisations would bind domain names to app ips. To my surprise, it turned out to be much simpler than I thought!
Initially, I assumed binding a custom domain to Grafana would involve complicated configurations and expensive domain purchases. Thanks to platforms like DuckDNS and No-IP.com, I realized you can achieve this seamlessly—even without spending a dime on domains.
For learning purposes, knowing how to map a domain to your Grafana dashboard and access it online is an invaluable skill. In this blog, I’ll walk you through the entire process: from configuring Nginx as a reverse proxy to securing the setup with SSL certificates.
Follow along if you want to unlock the full potential of Grafana by making your dashboards accessible to the world!
This blog is for intermediate individuals. I assume you already know to full fill prereqs.
Prerequisites
AWS Account
AWS EC2 machine
No-IP account and No-IP Hostname
Create an AWS EC2 machine with any Linux AMI
Install Prometheus
Connect to the created EC2 instance then install
Prometheus
and run it.Download using this link https://prometheus.io/download/ make sure to select the proper architecture of your VM and OS(linux). To know this run this command
uname -a
wget https://github.com/prometheus/prometheus/releases/download/v2.53.3/prometheus-2.53.3.linux-amd64.tar.gz
Extract the downloaded file and navigate to the extracted directory
tar -xvf tar -xvf prometheus-2.53.3.linux-amd64.tar.gz cd prometheus-2.53.3.linux-amd64/
Start Prometheus.
./prometheus
Our
prometheus
the server is started and listening on port9090
Install Grafana
Again connect to your instance in a different tab then install
Grafana
and run it. You can install thegrafana
using official documents or running the binaries of it. For the demo purpose, I am running using binaries from herewget https://dl.grafana.com/enterprise/release/grafana-enterprise-11.4.0.linux-amd64.tar.gz tar -zxvf grafana-enterprise-11.4.0.linux-amd64.tar.gz cd /home/ec2-user/grafana-v11.4.0/bin ./grafana-server
Note: Keep patience while extracting the downloaded
gz
file. It will take some time to complete the extraction. Also, When you run the./grafana-server
again this too takes some time.Now, Grafana has installed its listening on the port
3000
. To check the installation, We have to add the port3000
to the Security Group of ourec2
instance. So I am adding it and accessing mygrafana server
using its public IP.After, adding the port to SG, We are good to access our
grafana
server by thepublic IP
and port3000
Get the public IP from the EC2 instance and access Grafana on the browser.
Note: When you first time access the
grafana
, you can put uname:admin
and password:admin
Later you can change the password if you want.
Now, we have successfully installed
Prometheus
andGrafana
. However, we are accessing our grafana using the public IP (http://3.110.151.25:3000/) of ec2 instance. But we want to access it using a custom domain name likehttps://grafana-demo.ddns.net
Register a domain
It’s very easy to register a domain with free DNS provider no-ip for the study purpose. Although it’s not going to give all DNS enterprise options it can give you an option to create a DNS
A
record.
Register yourself at https://www.noip.com/sign-up
After signing up create a
hostname
in your account.Put the
hostname
, choose the domain and record type, and add the IP Address(put thepublic
IP
of yourec2
instance
) then Create the HostnameNow, here we have bound the domain to our
public IP
of theEC2
machine, you can test if the domain is properly resolving to thepublic IP
or not.dig grafana-demo.ddns.net
.
Install NGINX
To access our Grafana
server publicly, we need a proxy server to enable internet access. You can install a proxy server such as Nginx
or Apache
to achieve this. Nginx acts as a reverse proxy, forwarding client requests to the Grafana
server, while also handling load balancing, SSL termination, and caching. This ensures secure and efficient access to Grafana
over the internet. For the demo purpose, we ran both Promerheus
and Grafana
as binaries so let them run in the separate ec2
connect tabs. Open up a new tab to install NGINX
Install Nginx
sudo yum install nginx
Start and Enable Nginx
sudo systemctl start nginx sudo systemctl enable nginx
Create a Configuration File for Prometheus
sudo vi /etc/nginx/conf.d/grafana.conf
Add the following configuration
server { listen 80; server_name grafana-demo.ddns.net; location / { proxy_pass http://127.0.0.1:3000; # Replace with the local Prometheus address proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
Test Nginx Configuration:
sudo nginx -t
Restart Nginx:
sudo systemctl restart nginx
Verify Access: Open your browser and visit:
http://grafana-demo.ddns.net:3000
Secure Grafana
with HTTPS
To secure the grafana
server using SSL, use Certbot with Let's Encrypt.
Install Certbot
sudo yum install certbot python3-certbot-nginx
Obtain an
SSL
Certificate for our domaingrafana-demo.ddns.net
sudo certbot --nginx -d grafana-demo.ddns.net
- Follow the prompts to complete the SSL setup. At this stage, you will asked to press
Yes
orNo
Pressy
for all.
- Follow the prompts to complete the SSL setup. At this stage, you will asked to press
Add
443
port into the SG of theEC2
machine.Restart nginx
sudo systemctl restart nginx
Verify HTTPS Access: Open your browser and visit:
https://grafana-demo.ddns.net
To test it properly you can create a dashboard into
grafana
by addingprometheus
asdata source.
Issues faced
Issue: Nginx
was not getting installed.
Solution: Followed the steps from https://unix.stackexchange.com/questions/98025/yum-update-shows-killed
sudo fallocate -l 2G /swapfile
sudo mkswap /swapfile
sudo chmod 0600 /swapfile
sudo swapon /swapfile