1

Sometimes when configuring nginx and php-fpm I get message "File not found." I know this is beacause of wrong parameter SCRIPT_FILENAME, e.g.:

fastcgi_param   SCRIPT_FILENAME  /some/path$fastcgi_script_name;

I wonder is there a way to get exact full path of file which is cannot be found by php-fpm?

My php5-fpm.log has nothing, but:

[06-Jan-2014 11:14:33] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful
[06-Jan-2014 11:27:01] NOTICE: configuration file /etc/php5/fpm/php-fpm.conf test is successful

I've tried to change log_level option in php-fpm.conf to error and debug, but result remains the same

P.S. This line:

add_header X-My-Header /some/path$fastcgi_script_name;

doesn't do the trick, because add_header only works with successful responses, as I've read here

There is the nginx module, that allows to set header even with fail responses, but I think it should be an easier way to get file path.

Thank you.

Oleg
  • 266
  • 3
  • 17
  • Are your scripts in the same location as the root directory set in the Nginx configuration? – jaseeey Jan 06 '14 at 11:04
  • @Jason Ilicic it my case they are. But i'm looking for all-purpose decision. – Oleg Jan 06 '14 at 11:11
  • I'm unsure exactly how to get the path output. I use "fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;" which seems to work fine for me. I would also ensure that the permissions are appropriate for the files to be accessed by the PHP-FPM workers. – jaseeey Jan 06 '14 at 11:25
  • Also, you may be able to set a custom log_format, as mentioned here: http://serverfault.com/questions/404626/how-to-output-variable-in-nginx-log-for-debugging – jaseeey Jan 06 '14 at 11:30
  • my php5-fpm.log has rw------- permissions and is owned by root. and php-fpm workers are running by www-data. I've changed permissions to rw-rw-rw- but it is still not logging – Oleg Jan 06 '14 at 11:38
  • @JasonIlicic `log_format` works. By this time this is the best decision. Thank you! – Oleg Jan 06 '14 at 11:47
  • No problems, would be good if you could post your solution as an answer for future reference :) – jaseeey Jan 06 '14 at 22:47

1 Answers1

4

The solution would be the logging needed variables by nginx using log_format.

In the simplest case it may look like this (paste this code into http context):

log_format mylog '$fastcgi_script_name';
access_log  /var/log/nginx/access.log  mylog;

Then you can see results in access log file (in my case /var/log/nginx/access.log).

Another solution is to compile nginx with HttpHeadersMoreModule. This module allows you to manipulate http headers with much more flexibility than with nginx default add_header directive. So to view $fastcgi_script_name value you can write:

location ~ \.php$ {
    more_set_headers    "x-debug-header: $fastcgi_script_name";
    fastcgi_pass        127.0.0.1:9000;
    ...
}

Then you can see headers in Google Chrome DevTools in the Network tab (or similar tools in other browsers).

P.S. with HttpHeadersMoreModule you can also rewrite a Server header, if you need of course:

more_set_headers    "Server: my_server";

Good luck!

Oleg
  • 266
  • 3
  • 17