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.

Tim Jones
  • 93
  • 1
  • 2
  • 7

1 Answers1

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;
    }
    
mgorven
  • 30,615
  • 7
  • 79
  • 122
  • 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 '13 at 08:10
  • @TimJones See my edit. I'd go with the first option. – mgorven Feb 26 '13 at 16:54