Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx. Test which location used to process request

If you just want to see which block was used, and don't care about returning otherwise valid results, it might be more straight-forward to use return rather than add_header.

location / {
    return 200 'location 1';
}

location ~ /(\w+\-)\.html {
    return 200 'location 2';    
}

location @named {
    return 200 'location named';
}

A word of warning on this approach. I found it's a bad idea to use location as your debug header, since Location is a real header used by the HTTP response 301.

So if (like me) in your testing you end up with this:

HTTP/1.1 301 Moved Permanently
...
Location: http://mydomain.com/banana/
location: banana

Then your browser will freak out and report Duplicate headers received from server. So use locationdebug or something safe.


The add_header trick is how I would do it to.

I'm at work right now, so I can't test but you might possibly get something in the logfile i you set the error_log level to:

  • debug: you're nginx needs to be built using --with-debug for this to work, you can check that with the nginx -V command
  • notice: if debug logging isn't enabled