I am testing nginx and want to output variables to the log files. How can I do that and which log file will it go (access or error).
I am testing nginx and want to output variables to the log files. How can I do that and which log file will it go (access or error).
You can send nginx variable values via headers. Handy for development.
and you'll see in your browser's response headers:
I sometimes do this during local development.
It's also handy for telling you if a subsection is getting executed or not. Just sprinkle it inside your clauses to see if they're getting used.
So visiting a url like http://www.example.com/index.php will trigger the latter header while visiting http://www.example.com/img/my-ducky.png will trigger the former header.
You can return a simple string as HTTP response:
Or use interpolation for watching multiple variables at the same time:
You can set a custom access log format using the
log_format
directive which logs the variables you're interested in.Another option is to include the echo module when you build nginx, or install OpenResty which is nginx bundled with a bunch of extensions (like echo.)
Then you can simply sprinkle your configuration with statements like:
none of these answer the question as asked (log)
However, @Victor Aguilar - has a comment on this answer, that should be an answer! It says how to log variables, and it works. Thanks!
https://serverfault.com/a/404628/400075
i.e. in
/etc/nginx/nginx.conf
error_log /var/log/nginx/error.log debug;
results in the following type of logging: