How to remove mod_pagespeed from access.log

If you have mod_pagespeed installed on your webserver you may notice the following lines in access.log file:

Depending on the size of your website requests from mod_pagespeed can add flood your logfiles and their size will be significantly larger. Here is how you can exclude mod_pagespeed requests from access.log file

Apache

To exclude mod_pagespeed requests from Apache access.log file use SetEnvIf directive (for more information and examples see the article How not to log certain requests in Apache).

You can filter mod_pagespeed requests by IP address or by User-Agent. In the global, vhost configuration or in .htaccess file define the following:

or

where 192.168.0.154 is *ipofserver* from the log above.

Now find the CustomLog directive in your Apache configuration, e.g.

and add env=!dontlog to the line:


Save the configuration file and restart Apache.

Nginx

For Nginx we use similar approach, filter by IP:

where 192.168.0.154 is *ipofserver* from the log above.

By User-Agent:

Save config files and restart Nginx.

Good luck!

Want me to do this for you? Drop me a line: itgalaxyzzz {at} gmail [dot] com