Dec 14, 2014

0 Log google bot access in seperate Nginx logfile

You cannot use " access_log " in an " if " statement.
You will get error: 
[emerg] "access_log" directive is not allowed here.

# Create logfile google.log
# And set access rights

     touch /var/log/nginx/google.log
     chown www-data:www-data /var/log/nginx/google.log

# Add configuration to " sites-enabled/[your_site_name] "
# It must be inside of " server " block.

     nano /etc/nginx/sites-enabled/wordpress


#----------------Configuration Code-------------------#

# LOG google bot seperate #

if ($http_user_agent ~* (googlebot) ) {
set $crawler 'yes';
}
location ~ .* {
if ($crawler = 'yes') {
        access_log /var/log/nginx/google.log;
        return 200;
        }
}


#----------------Configuration Code-------------------#

0 comments :

Post a Comment

Comment: