Skip to content

NUT on Nginx with fcgiwrap

Logan Marchione edited this page Feb 25, 2017 · 3 revisions

I'm assuming you have Nginx installed and have a working configuration. I'm also assuming you're running Debian or a derivative.

Unlike Apache, Nginx doesn't have built in support for executing CGI scripts, so a helper application is needed to handle dynamic content. In this case, that package is fcgiwrap.

Start by installing the packages.
sudo apt-get update && sudo apt-get install nut-cgi fcgiwrap

Edit the configuration file at /etc/nut/hosts.conf and add the following line (replace cyberpower1 with the friendly name of your UPS). This step is part of the Apache instructions as well.
MONITOR cyberpower1@localhost "CyberPower CP1500PFCLCD"

The HTML files that come from the nut-cgi package have links to /cgi-bin/nut/upsstats.cgi and /cgi-bin/nut/upsset.cgi. We need two locations:

  1. a location (named /nut) for the HTML files located in /usr/share/nut/www
  2. a location (named /cgi-bin/) for the CGI files located in the standard directory of /usr/lib

The location block looks like this.

server {                                                                                                                                                                                  
...
        location /nut {
        alias /usr/share/nut/www/;
        try_files $uri $uri/ /index.html;
        }

        location /cgi-bin/ {
                gzip off;
                root /usr/lib;

                include fastcgi_params;
                fastcgi_pass unix:/var/run/fcgiwrap.socket;
                fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        }
...
}

Change ownership of the CGI files and start/restart the necessary services.

sudo chown www-data:www-data /usr/lib/cgi-bin/nut/*.cgi
sudo systemctl restart fcgiwrap.service
sudo systemctl restart fcgiwrap.socket
sudo systemctl restart nginx

Then, visit your stats page at http://your_IP/nut

If you want to visit the settings/admin page, you will need to edit the configuration file at /etc/nut/upsset.conf and uncomment the line below. This step is part of the Apache instructions as well.
###I_HAVE_SECURED_MY_CGI_DIRECTORY

https://loganmarchione.com/2017/02/raspberry-pi-ups-monitor-with-nginx-web-monitoring/

Clone this wiki locally