# Log to a file inside a location block?

**URL:** <https://www.ruby-forum.com/t/log-to-a-file-inside-a-location-block/244508>\
**Category:** NGINX\
**Created:** [April 23, 2016, 9:35pm UTC](https://www.ruby-forum.com/t/log-to-a-file-inside-a-location-block/244508 "2016-04-23T21:35:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [April 23, 2016, 9:35pm UTC](https://www.ruby-forum.com/t/log-to-a-file-inside-a-location-block/244508/1 "2016-04-23T21:35:30Z")

</div>

Hello,

Is there any way to log to a file which location block is taken? I’ve  
had times when I’ve messed up regular expressions in location blocks and  
it was difficult to track down the issue. Is there any option equivalent  
to this pseudocode?

location ~ ^/prepend(a|b) {  
logtofile “/prepend(a|b)” filepath;  
# Continue normal stuff…  
}

Of course logtofile could also be a “print” or really anything that gets  
the information out somewhere.

My nginx version is the following:

$ nginx -v  
nginx version: nginx/1.4.6 (Ubuntu)

$ lsb\_release -a  
No LSB modules are available.  
Distributor ID: Ubuntu  
Description: Ubuntu 14.04.2 LTS  
Release: 14.04  
Codename: trusty

Thanks for any help!

Cheers,  
Thomas
