Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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).

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

You can set a custom access log format using the log_format directive which logs the variables you're interested in.

share|improve this answer
thanks, and I guess there is no easier way to output one variable by itself? –  lulalala Jul 4 '12 at 5:39
@lulalala Not that I know of. –  mgorven Jul 4 '12 at 5:42
add comment

If you're in a development environment, you can send variables via headers.

add_header X-uri "$uri";

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.

location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt)$ {
    add_header X-debug-message "A static file was served";

location ~ \.php$ {
    add_header X-debug-message "A php file was 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.

share|improve this answer
add comment

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:

echo "args: $args"
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.