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.

How do I get apache to prevent http requests from being logged on a directory basis? I want to do something alike

<IfModule mod_userdir.c>
    UserDir public_html

    <Directory /home/*/public_html/nolog>
        Options NoAccessLog
    </Directory>
</IfModule>
share|improve this question

1 Answer 1

up vote 7 down vote accepted

You can set an environment flag whenever a specific URL is requested and filter logging based on that:

<IfModule mod_userdir.c> 
    UserDir public_html 

    SetEnvIf Request_URI "/nolog" dontlog
    CustomLog /var/log/apache2/useraccess_log combined env=!dontlog
</IfModule> 

All the related reading can be found at http://httpd.apache.org/docs/2.2/env.html Section "Using Environment Variables - Conditional Logging"

What these two lines do is, whenever a Client requests a URL that contains the string "/nolog" it sets the Environment Variable dontlog.

In the next line the option "env=!dontlog" tells the CustomLog directive to log Client access unless the variable dontlog is set. The ! negates the directive. If you would leave the ! so that it reads "env=dontlog" than it would only log access to paths that have "/nolog" in the requested URL.

EDIT: I removed the ^ in the "/nolog" regexp to work with your example and added some more explanation.

share|improve this answer
    
Doesn't work for me - access is still logged. Can you please elaborate your a bit more and integrate it in the given mod_userdir example? Thanks! –  nidi Mar 7 '10 at 11:38
    
Ok, I updated my answer to match your example. Basically you just leave out the ^ in the regexp. "^/nolog" would only match URLs like example.com/nolog/foobar but since you always have a Username first like example.com/~user/nolog/foobar it wouldn't match. So just remove the ^ and it should work. Of course you can further tweak that regexp to include matching of the username, etc. Now it would match every URL that has the string "/nolog" in it. –  Lukas Loesche Mar 7 '10 at 13:19
    
Great! Thanks for the explanation! –  nidi Mar 7 '10 at 16:24
    
I had trouble getting this to work ( apache 2.2.3 ) before switching from using graceful to using apachectl restart. Then it worked just fine. –  anttiR Aug 24 '12 at 11:03

Your Answer

 
discard

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.