0

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.

3
  • try just changing location line from "location /cacti {" to "location / {" Feb 25, 2013 at 15:58
  • The "location /" already has a root of /var/www - Updated post to add this
    – Tim Jones
    Feb 25, 2013 at 16:01
  • might be worth noting that you are missing a semi-colon after index.html index.htm May 27, 2014 at 8:41

1 Answer 1

1

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;
    }
    
2
  • When I use the alias directive, the pages fail to load and my NginX log shows that PHP-FPM is still looking for the scripts in /usr/share/cacti/cacti/...
    – Tim Jones
    Feb 26, 2013 at 8:10
  • @TimJones See my edit. I'd go with the first option.
    – mgorven
    Feb 26, 2013 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .