Search code examples
portgrafana

Access Grafana from another machine on the same network


I installed Grafana using the instructions on the website on a server we have. When I curl http://localhost:3000/ from this specific machine I got a response back. The same if I curl http://ip-address-of-grafana-machine:3000/

However, when I try to curl the http://ip-address-of-grafana-machine:3000/ from another machine on the same network I got a connection timeout. I tried everything I found online but I still have a problem.

  • All ports are accessible within the network for the machine where Grafana is installed according to our IT services.
  • The machine does not have a firewall installed. I enabled/disabled ufw manually. When enabled I allowed port 3000 but still no luck.

I believe that the problem has to do with something pretty basic related to ports but I cannot figure out as I am not a network expert. This makes me believe that Grafana is accessible by default from the machine it is installed and if you need to access it from another machine you need to make some changes.

I also played with all the configuration properties in the [server] section of the /etc/grafana/grafana.ini but I had no luck.

Am I missing something very basic knowledge here?


Solution

  • I solved this using Apache reverse proxy. Firstly, I added the following into my 000-default.conf found under /etc/apache2/sites-enabled/

    ServerName http://ip-address-of-grafana-machine
    RewriteEngine on
    RewriteRule ^/?$ /grafana/ [R=permanent,L]
    <Location "/grafana">
        ProxyPass http://localhost:3000
    </Location>
    ProxyPassReverse /grafana http://localhost:3000
    

    I had to enable the reverse proxy modules in Apache to make it work (remember t restart Apache to load these). If not, Apache wouldn't start.

    sudo a2enmod proxy
    sudo a2enmod proxy_http
    sudo systemctl restart apache2
    

    As, I wanted to access the grafana UI through the address http://ip-address-of-grafana-machine/grafana (that's why I have the /grafana path in the 000-default.conf) I set the grafana.ini parameter root_url found under /etc/grafana to root_url = http://ip-address-of-grafana-machine:3000/grafana (remember to remove the ; at the beginning and make sure you put the port number).