0

I have a Debian 8 with Apache. My /etc/apache2/sites-available/000-default.conf is like the follwing.
How, and in which config file, can I ask Apache to not log in /var/log/apache2/other_vhosts_access.log the traffic coming from http://www.mysite2.org or from http://www.mysite3.org/subdir/ ? All the rest should be logged to the same file other_vhosts_access.log as usual.

<VirtualHost *:80>
  ServerName www.mysite1.org
  DocumentRoot /home/www/mysite1
  <Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from all
    Require all granted
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  ServerName www.mysite2.org
  DocumentRoot /home/www/mysite2
  <Directory />
  ...
  </Directory>
</VirtualHost>

<VirtualHost *:80>
  ServerName www.mysite3.org
  DocumentRoot /home/www/mysite3
  <Directory />
  ...
  </Directory>
</VirtualHost>

+ 10 other virtual hosts
0

each virtual host needs a deffinition of errorlog and common log, without these the default log is used, also note, it's worth creating a default vhost which catches all traffic that is not for one of your domains (people who point their dns at your website). This can have bad serp consequences as it's dupe content.

so, in each vhost;

    ErrorLog "logs/web1-error_log"
    CustomLog "logs/web1-access_log" common

    ErrorLog "logs/web2-error_log"
    CustomLog "logs/web2-access_log" common

UPDATE:

didn't see the part on not logging a particular dir, this would be achived by setting an enviroment var.

  • Does CustomLog "logs/web2-access_log" common need to be in the /etc/apache2/sites-available/000-default.conf file, inside <VirtualHost *:80></VirtualHost>? – Basj Oct 25 '16 at 8:06
  • Something else, as asked in question, how to not log trafic from a subdir of a virtual host? i.e. mysite3.org traffic should be logged, but mysite3.org/subdir not logged ? – Basj Oct 25 '16 at 8:07
  • customlog should be defined in every vhost, every vhost should have it's own log file as best practice. – mikejonesey Oct 25 '16 at 8:34
  • in which configuration file should we set custom log? – Basj Oct 25 '16 at 9:05
  • inside the virtualhost – mikejonesey Oct 25 '16 at 12:41
0

Thanks to @MikeJonesey for his answer. To add more details, here is the solution, to put in /etc/apache2/sites-available/000-default.conf:

<VirtualHost *:80>
  ServerName www.mysite3.org
  DocumentRoot /home/www/mysite3
  <Directory />
  ...
  </Directory>
  SetEnvIf Request_URI "^/subdir(.*)$" dontlog
  CustomLog ${APACHE_LOG_DIR}/other_vhosts_access.log vhost_combined env=!dontlog
</VirtualHost>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.