fastcgi_catch_stderr
The 'fastcgi_catch_stderr' directive controls whether NGINX captures standard error output from FastCGI applications.
Description
The 'fastcgi_catch_stderr' directive is used within the contexts of 'http', 'server', and 'location' to manage the handling of error messages generated by FastCGI applications. When enabled, any messages sent to standard error by the FastCGI application will be captured and logged by NGINX, allowing for easier debugging and visibility into application issues directly through the NGINX error log. By default, this directive is set to off, meaning NGINX only captures standard output unless this is explicitly turned on.
This directive takes a single argument: ‘on’ or ‘off’. By setting it to ‘on’, the developer can obtain valuable error messages that may be critical for diagnosing issues in FastCGI applications, especially in production environments where seeing these logs can preemptively point out potential errors in code execution. It is important to note that excessive logging may lead to performance degradation if the application generates a lot of error output, hence careful management of logging levels is recommended.
Properly utilizing 'fastcgi_catch_stderr' enhances the overall maintainability of FastCGI applications by centralizing error logging through NGINX while also providing developers clear insights into runtime errors that might not appear elsewhere. However, when using this directive, it should be balanced with the performance considerations of logging at higher verbosity levels, especially under high traffic conditions.
Config Example
location /api {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_catch_stderr on;
}Ensure that your FastCGI application is configured to output errors to stderr; otherwise, this directive will have no effect.
Be aware that enabling this feature may increase the volume of logs, potentially leading to performance impacts under high load.