Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
try just changing location line from "location /cacti {" to "location / {" –  Andrei Mikhaltsov Feb 25 '13 at 15:58
    
The "location /" already has a root of /var/www - Updated post to add this –  Tim Jones Feb 25 '13 at 16:01
    
might be worth noting that you are missing a semi-colon after index.html index.htm –  Barry Chapman May 27 at 8:41
add comment

1 Answer 1

up vote 0 down vote accepted

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|improve this answer
    
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 8:10
    
@TimJones See my edit. I'd go with the first option. –  mgorven Feb 26 '13 at 16:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.