To reduce disk space usage and log noise, NGINX is configured with a very conservative error logging configuration of warn
error_log /var/log/nginx/error.log warn
While the default setting has benefits, there is the tradeoff that troubleshooting various problems, such as a 500 error, is not feasible with this default setting because 500 errors and other potential issues are not included in the log.
You may use the following techniques to increase your ability to diagnose problems that you may encounter.
Please note, there is no need to edit the default error_log directive
The default error_log directive is configured in the main ( AKA top level: /etc/nginx/nginx.conf ) configuration and is applied globally.
Changes made to the default error_log directive:
- Can unnecessarily increase the noise in the error log, which makes it more challenging to find the problem
- Are more likely to cause the server to run out of disk space
- Are more likely to hinder server performance due to increased disk write operations
- Will be overwritten by cPanel whenever the configuration is rebuilt
- Are better implemented in other ways
The error_log directive is designed in a way that allows the administrator to override the default very easily, as explained in the below sections.
The possible logging levels are: debug, info, notice, warn(default), error, crit, alert, and emerg.
Generally, when trying to troubleshoot a problem, the best method is to use the debug log level and then only decrease the log level if you find that the debug level is too verbose.
Enabling Debug Logs For An Individual Domain / Site
1. log in to the server via SSH or Terminal as the root user
2. Create a configuration file for the domain if one does not already exist. Please be sure to replace the cPanel username and domain name in the following command to match yours, but in lowercase letters:
3. Add the following configuration to that file, and be sure to replace the domain name with your own:
error_log /var/log/nginx/domains/EXAMPLEDOMAIN.tld-custom_debug.log debug;
4. Restart NGINX:
Also note, that you don't need to rebuild the configuration because includes in the specified directories are built into the main configuration through wildcard matching.
Enabling Debug Logs For All Domains That A User Owns
Perform the same exact steps as are outlined in above, except put the configuration at the following location on step 2. Do not include the "location" clause for this configuration.
And set the log file location to the following in step 3, replacing the username as required:
error_log /var/log/nginx/domains/USERNAMEHERE-custom_debug.log debug;
Enabling Debug Logging Server Wide
Enabling debug logging server wide can cause a problem because it can use an excessive amount of disk space very quickly and may potentially cause the server to run out of disk space entirely. It also will increase the I/O resources used and could hinder performance. Only keep debug enabled for a very short time and monitor the server closely.
Perform the same steps as above but put the configuration in the following location in step 2:
And update the log location to the following in step 3. Do not include the "location" clause for this configuration.
error_log /var/log/nginx/error.log debug;