如何使 nixos 上的 grafana 在本地网络中可用

How to make grafana on nixos available in local network

我的笔记本电脑和我的 nixos-server (hostname=nixos) 都连接到我的路由器 (fritz.box)。我可以通过 ping (ping nixos.fritz.box) 和 ssh (ssh username@nixos.fritz.box).

访问 rooter

我想要的是按照this guide的第一部分在nixos上设置grafana。然后我希望能够从我的笔记本电脑访问 grafana。

在服务器上,我已将 nixos 配置为 运行 grafana 和反向代理 (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";

不幸的是,我无法从笔记本电脑访问 grafana 网络界面。

我尝试更改 services.grafana.domain 的值以及我在浏览器中输入的内容 (firefox/curl),这是我得到的结果:

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

尤其是最后两行让我很困惑。

服务器上的

netstat -an | grep LISTEN 给我这个:

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

我不知道如何让grafana在本地网络可用。有人可以帮我吗?

(我知道这个问题有点类似于,但是那里的解决方案对我没有帮助)

添加以下行解决了我的问题(感谢@Tch):

nginx.service.enable = true;