april breeze

another web programmer

photo gallery

[Apache] logging images with external referrer

<IfModule mod_setenvif.c>  
    SetEnvIfNoCase Request_URI "\.jpg$" no-log env-image
    SetEnvIfNoCase Request_URI "\.jpeg$" no-log env-image
    SetEnvIfNoCase Request_URI "\.gif$" no-log env-image
    SetEnvIfNoCase Request_URI "\.png$" no-log env-image
</IfModule>

<VirtualHost *:80>  
    DocumentRoot /path-to-document-root
    ServerName www.example.com

    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined env=!no-log

    <IfModule mod_setenvif.c>
        SetEnvIfNoCase Referer (.+\.)?example\.com not-logging-image-referer=1
        SetEnvIfNoCase Referer ^$ not-logging-image-referer=1
        SetEnvIf not-logging-image-referer 1 !env-image
    </IfModule>
    CustomLog ${APACHE_LOG_DIR}/example.com-image-referer.log combined env=env-image
</VirtualHost>  
  1. access log - not logging images
  2. another log - logging images with external referrer
    (emulate logical AND : http://stephane.lesimple.fr/blog/2010-01-28/apache-logical-or-and-conditions-with-setenvif.html )

... 다 만들어놓고 보니 static file은 Nginx에서 처리하게 해놨던게 생각나서.. 쓸모없어짐-_-...

comments powered by Disqus