Search code examples
nginxnetwork-programmingportgrafananixos

How to make grafana on nixos available in local network


My laptop and my nixos-server (hostname=nixos) are both conected to my router (fritz.box). I can access the rooter via ping (ping nixos.fritz.box) and ssh (ssh [email protected]).

network diagram

What I want is to follow the first part of this guide to set up grafana on nixos. I then want to be able to access grafana from my laptop.

On the server I have configured nixos to run both grafana and a reverse proxy (nginx):

  services.grafana = {
    enable = true;
    domain = "grafana.nixos.fritz.box";
    port = 2342;
    addr = "127.0.0.1";
  };

  # nginx reverse proxy for grafana
  services.nginx.virtualHosts.${config.services.grafana.domain} = {
    locations."/" = {
      proxyPass = "http://127.0.0.1:${toString config.services.grafana.port}";
      proxyWebsockets = true;
    };
  };

  # Open ports for http and https
  networking.firewall.allowedTCPPorts = [ 80 443 ];

  system.stateVersion = "21.03";

Unfortunatelly I can't access the grafana webinterface from my laptop.

I tried changing around the value of services.grafana.domain and what I type into my browser (firefox/curl), here is what I got:

services.grafana.domain argument of curl output of curl
grafana.nixos.fritz.box http://grafana.nixos.fritz.box/ curl: (6) Could not resolve host: grafana.nixos.fritz.box
grafana.nixos.fritz.box https://grafana.nixos.fritz.box/ curl: (6) Could not resolve host: grafana.nixos.fritz.box
grafana.nixos.fritz.box http://nixos.fritz.box/ curl: (52) Empty reply from server
grafana.nixos.fritz.box https://nixos.fritz.box/ curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to nixos.fritz.box:443
nixos.fritz.box http://nixos.fritz.box/ curl: (52) Empty reply from server
nixos.fritz.box https://nixos.fritz.box/ curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to nixos.fritz.box:443
grafana.localhost (on the server) http://grafana.localhost curl: (7) Failed to connect to grafana.localhost port 80: Connection refused
grafana.localhost (on the server) https://grafana.localhost curl: (7) Failed to connect to grafana.localhost port 443: Connection refused

Especially the last 2 lines leave me perplexed.

netstat -an | grep LISTEN on the server gives me this:

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:2342          0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
unix  2      [ ACC ]     STREAM     LISTENING     1837     /run/systemd/private
unix  2      [ ACC ]     STREAM     LISTENING     1841     /run/systemd/userdb/io.systemd.DynamicUser
unix  2      [ ACC ]     SEQPACKET  LISTENING     1853     /run/systemd/coredump
unix  2      [ ACC ]     STREAM     LISTENING     1862     /run/systemd/journal/stdout
unix  2      [ ACC ]     SEQPACKET  LISTENING     1868     /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     26958    /var/run/nscd/socket
unix  2      [ ACC ]     STREAM     LISTENING     1905     /run/systemd/journal/io.systemd.journal
unix  2      [ ACC ]     STREAM     LISTENING     12193659 /run/user/1001/bus
unix  2      [ ACC ]     STREAM     LISTENING     12205464 /run/user/1001/systemd/private
unix  2      [ ACC ]     STREAM     LISTENING     13312    /nix/var/nix/daemon-socket/socket
unix  2      [ ACC ]     STREAM     LISTENING     18416    /var/run/dhcpcd.sock
unix  2      [ ACC ]     STREAM     LISTENING     18418    /var/run/dhcpcd.unpriv.sock
unix  2      [ ACC ]     STREAM     LISTENING     13308    /run/dbus/system_bus_socket

I don't know how to make grafana available in the local network. Can someone help me with that, please?

(I know this question is somewhat similar to this one, but the solution there doesn't help me)


Solution

  • Adding the following line solved my problem (thanks to @Tch):

    services.nginx.enable = true;