Php – Need helpful error message from mod_proxy_fcgi

apache-2.2apache-2.4PHP

When a non-existent php script is requested, mod_proxy_fcgi provides a rather useless error message, basically just saying

[proxy_fcgi:error] .... AH01071: Got error 'Primary script unknown\n'

This server is using Apache 2.4.6 (Centos 7), with php handling configured as:

<FilesMatch \.php$>
  SetHandler "proxy:fcgi://127.0.0.1:9000"
</FilesMatch>

I really would like to know the actual script name, because it may contain useful information (such as indicating a defective link, an error in a page name, or merely showing that it is just another fool hunting for a server with unprotected wp-login.php).

I tried changing LogLevel from info to debug, but then the error log was also filled with valid php script access details, which makes quite a mess of the error log, since those are not actually errors.

Is there some way to get a more useful proxy_fcgi error message which includes the actual script name for non-existent php scripts?

Best Answer

You can define ErrorLogFormat including the %L and then do the same in your CustomLog format %L

That will make Apache log a specific id which will bind an errorlog entry into the access log entry and then all you need to do is grep.

Example:

ErrorLogFormat "[%{u}t] [%-m:%l] [%L] [pid %P:tid %T] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i"

LogFormat "%h %l %u [%L] %t \"%r\" %>s \"%{Referer}i\" \"%{User-Agent}i\"" combined

So next time, when you see an error, you check the ID in it and grep the access.log for the same id