Nginx & fcgiwrap, logging perl errors to error log

nginxperlspawn-fcgi

This is similar to this question, which got no responses:
How to debug CGI over fcgiwrap/nginx

How do I get perl errors to be automatically placed in the nginx error log? Right now, when there is any perl error, the following message goes in the error log:

2014/05/11 22:43:48 [error] 1730#0: *5 connect() failed (111: Connection refused) while connecting to upstream, client: localhost, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost"

This is completely useless for debugging. I can use something like CGI::Carp qw{fatalsToBrowser}, but this is not optimal. It would be better to have it logged to a server-side file.

Best Answer

You can use this solution to send both STDOUT and STDERR to any log file you have access to write to, including your nginx error.log. Though it'd likely be more helpful to send it to a different file. Simply remove the STDOUT entries, if you only want STDERR output.