Is there any way to make Apache create an access log for a single folder?

Files in this folder will be accessed very often, and I would prefer to avoid using any sort of script to generate the log.

An example would be something like:


Ideally I'd like Apache to keep an access log of these files in rotation ie:


If that's possible, I could then create a script to read the log on demand.

I cannot use a subdomain as these files must go through HTTPS and we haven't got a wildcart certificate.

Any ideas?

UPDATE: I expect some of these files will be accesses more often than 10-20 times a second. It's an update notifier. One of this files is a huge binary file and the other just a text containing latest version.


You could use environment variables with mod_setenvif.

But why shouldn't you? Its a huge security risk! For example, such a function built into Apache would open up a DoS opportunity by overloading the number of file handles. For this example, assume you can only have 16 files open on your server at once. I can now wipe out those file descriptors by iterating through /1, /2, /16--there are now 16 logs that Apache must maintain.

The safest way (but by no means the most resource friendly) would be to pipe each request to a script:

CustomLog "|/some/script/for/parsing/logs" combined

This won't eliminate the above options--but it will allow you to have a lot more flexibility in where the logs go, as well as alleviating Apache's responsibility in maintaining your server's stability.

Finally, what you should be doing is exactly what you don't want to do--processing these after the fact. What you're looking for is some sort of aggregate parsing--i.e., which lines dealt with some unique set of directories. How often is this realistically going to be used? If its not often, what's wrong with just greping the logs and displaying its output? These are the kinds of questions you should ask first.

| improve this answer | |
  • Unfortunately, my answer remains the same--its not a good idea to dynamically create log files. – Andrew M. May 14 '12 at 20:49
  • Can "CustomLog" be used within .htaccess somehow? – WooDzu May 14 '12 at 21:02
  • No, and for the same reason--the logs need to be started BEFORE everything else. On shared hosting as well, this could lead to the same security exploits I mentioned above. – Andrew M. May 14 '12 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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