Hosting Cacti install from NginX

5,193

The root directive still results in the URL path being appended, so if the root is /usr/share/cacti and the path is /cacti the directory is /usr/share/cacti/cacti. You can do one of two things:

  1. Since your URL path matches the directory, set the root one level higher:

    location /cacti {
        root /usr/share;
        ...
    }
    
  2. Use the alias directive, which doesn't append the URL path. This approach will require modifying the SCRIPT_FILENAME parameter passed to PHP however.

    location /cacti {
        alias /usr/share/cacti;
        ...
        fastcgi_param SCRIPT_FILENAME /usr/share$request_filename;
    }
    
Share:
5,193

Related videos on Youtube

Tim Jones
Author by

Tim Jones

Updated on September 18, 2022

Comments

  • Tim Jones
    Tim Jones over 1 year

    I have having an issue with hosting a Cacti installation from NginX.

    I have cacti installed under /usr/share/cacti and the below block in my default NginX config file.

    location / {
        root /var/www;
        index index.html index.htm
    }
    
    location /cacti {
        root /usr/share/cacti;
        index index.php index.html index.htm;
        location ~ \.php$ {
            try_files $uri =404;
            include fastcgi_params;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$request_filename;
        }
    }
    

    The problem as I can see is that the NginX error log is full of errors that "/usr/share/cacti/cacti/index.php" doesn't exist.

    For now I have simply added the extra directory to cacti, but I can't figure how to get NginX to 'drop' the '/cacti/' prefix from the URI when processing the page requests (and passing them on to PHP5-FPM)

    Any help would be appreciated.

    • Andrei Mikhaltsov
      Andrei Mikhaltsov about 11 years
      try just changing location line from "location /cacti {" to "location / {"
    • Tim Jones
      Tim Jones about 11 years
      The "location /" already has a root of /var/www - Updated post to add this
  • mgorven
    mgorven about 11 years
    @TimJones See my edit. I'd go with the first option.