Logs Apache : Différence entre versions
m |
(Aucune différence)
|
Version actuelle en date du 12 novembre 2015 à 03:21
Cet article présente la mise en place des logs, et la gestion de celles-ci, sous Apache pour une installation sur Ubuntu.
Votre avis
Current user rating: 66/100 (2 votes)
|
|
Configuration
Généralement, deux logs sont mises en place pour tracer:
- Les accès dans un fichier access.log
- Les erreurs dans un fichier error.log
Cette configuration s'effectue au niveau de la déclaration du Host.
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/default
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/default>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
# Deny from all
# Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
Alias /dev/ "/var/opt/dev/"
<Directory "/var/opt/dev/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
# Deny from all
# Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Dans le cadre de l'installation sous Ubuntu, la variable ${APACHE_LOG_DIR}
sera remplacée par /var/log/apache2
, configurée dans le fichier /etc/apache2/envvars
.
# envvars - default environment variables for apache2ctl
# this won't be correct after changing uid
unset HOME
# for supporting multiple apache2 instances
if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
SUFFIX="-${APACHE_CONFDIR##/etc/apache2-}"
else
SUFFIX=
fi
# Since there is no sane way to get the parsed apache2 config in scripts, some
# settings are defined via environment variables and then used in apache2ctl,
# /etc/init.d/apache2, /etc/logrotate.d/apache2, etc.
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
export APACHE_PID_FILE=/var/run/apache2$SUFFIX.pid
export APACHE_RUN_DIR=/var/run/apache2$SUFFIX
export APACHE_LOCK_DIR=/var/lock/apache2$SUFFIX
# Only /var/log/apache2 is handled by /etc/logrotate.d/apache2.
export APACHE_LOG_DIR=/var/log/apache2$SUFFIX
## The locale used by some modules like mod_dav
export LANG=C
## Uncomment the following line to use the system default locale instead:
#. /etc/default/locale
export LANG
## The command to get the status for 'apache2ctl status'.
## Some packages providing 'www-browser' need '--dump' instead of '-dump'.
#export APACHE_LYNX='www-browser -dump'
## If you need a higher file descriptor limit, uncomment and adjust the
## following line (default is 8192):
#APACHE_ULIMIT_MAX_FILES='ulimit -n 65536'
Droits d'accès
Par défaut, les droits d'accès sur les fichiers de logs ne permettent qu'aux compte root
de les modifier, et au groupe adm
de les consulter.
drwxr-x--- 2 root adm 4096 2012-03-09 01:51 ./ drwxr-xr-x 21 root root 4096 2012-03-10 07:58 ../ -rw-r----- 1 root adm 3187646 2012-03-10 11:31 access.log -rw-r----- 1 root adm 50140004 2012-03-04 07:47 access.log.1 -rw-r----- 1 root adm 87916 2012-03-10 11:31 error.log -rw-r----- 1 root adm 99040 2012-03-04 07:47 error.log.1 -rw-r----- 1 root adm 0 2012-02-28 07:38 other_vhosts_access.log -rw-r--r-- 1 root root 28045 2012-02-27 22:41 other_vhosts_access.log.1
Mais comment est-ce que ces valeurs sont spécifiées ? Ceci est réalisé par la configuration de l'outil Logrotate, dont la configuration se trouve dans le fichier /etc/logrotate.d/apache2
.
/var/log/apache2/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
/etc/init.d/apache2 reload > /dev/null
endscript
}
Dans certain cas, rawlog sous Awstats par exemple, l'accès à ces logs est nécessaire. Il suffit de modifier la configuration en changeant le groupe par exemple.
/var/log/apache2/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
#create 640 root adm
create 640 root www-data
sharedscripts
postrotate
/etc/init.d/apache2 reload > /dev/null
endscript
}
Il faut également penser à modifier les droits d'accès sur le répertoire /var/log/apache2
.
Le script est légèrement modifié, pour la version 12.04 de Ubuntu, mais le paramétrage d'accès aux logs doit être modifié comme dans le cas précédent
/var/log/apache2/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
#create 640 root adm
create 640 root www-data
sharedscripts
postrotate
/etc/init.d/apache2 reload > /dev/null
endscript
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
run-parts /etc/logrotate.d/httpd-prerotate; \
fi; \
endscript
}