3

I am trying to set a SetEnvIf variable in apache2 and exclude it in CustomLog in order to stop my logs from filling up. I want to match a regex and also specific IPs.

I tried to follow the instructions listed at the site below, but it does not seem to be working. http://www.howtoforge.com/setenvif_apache2

Noob alert: The site doesn't specify where to put the SetEnvIf statement, so I put them in apache2.conf and also /sites-available/default.

Here is an example of what I want to filter in access.log:

    x.x.x.x - - [06/Sep/2014:15:02:35 -0500] "HEAD /dir/dir2/file1/file2.gif HTTP/1.1" 200 224 "-" "-"

    127.0.0.1 - - [06/Sep/2014:15:02:30 -0500] "GET /foo1/foo2.php? HTTP/1.0" 200 28956 "-" "Wget/1.12 (linux-gnu)"

So in apache2.conf and /sites-available/default, i put this:

    SetEnvIf Request_URI "HEAD /dir/" dontlog
    SetEnvIf Request_Addr "127\.0\.0\.1" dontlog
    SetEnvIf Request_Addr "::1" dontlog

And added env=!dontlog to the existing /default/CustomLog entry:

    CustomLog ${APACHE_LOG_DIR}/access.log combined env=!dontlog

I then executed apachectl graceful .

Nothing is changing.

3
  • Try "HEAD /dir/.*"
    – gtirloni
    Sep 6, 2014 at 22:58
  • That doesn't do anything. As far as I can tell, it can be a regular expression and if it matches it should be skipping the logging. It's acting like it's not even reading the config files. Maybe there are setting elsewhere I'm supposed to change. Sep 7, 2014 at 0:25
  • Still haven't found a solution, even on other sites. Seems like it should be working. Is there an apache setting that can preclude setting variables such as these? Sep 14, 2014 at 4:52

1 Answer 1

3

The filters only need to be added to one config. Try removing what you added to apache2.conf and keep everything in /sites-available/default.

For example, if you want to filter out search bots from your logs, the end of your config file will look like:

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    # Filter all search bots from the access log.
    SetEnvIfNoCase User-Agent googlebot dontlog
    SetEnvIfNoCase User-Agent bingbot dontlog
    SetEnvIfNoCase User-Agent baiduspider dontlog

    # Custom Log location + options
    CustomLog ${APACHE_LOG_DIR}/access.log combined env=!dontlog
</VirtualHost>

Also, when you do apachectl graceful, it can take a while. If you're just testing the changes, delete the log files, do apachectl graceful, and when you see the log files get re-created, you'll know they are populated using the new filter options you specified.

3
  • Trying it out now...I initially typed up a response and was going to delete this reply but it won't let me. Sep 29, 2014 at 17:23
  • Good new: It appears if I change my regular expression to just "dir", it is not logged! However, I am still getting all the 127.0.0.1 and ::1 logged. Here is my syntax that doesn't seem to be working: SetEnvIf Request_Addr "127\.0\.0\.1" dontlog SetEnvIf Request_Addr "::1" dontlog Sep 29, 2014 at 17:33
  • FIXED: I needed it to be "Remote_Addr", not "Request_Addr". Sep 29, 2014 at 17:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .