1. Define the log format in the master configuration file
[Email protected] ~]# vim/usr/local/apache2/conf/httpd.conf
<ifmodule log_config_module> Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" Combin Ed # Default defined log format, combined is the log format name logformat "%h%l%u%t \"%r\ "%>s%b" common # Default defined log format, C Ommon is a log format name </IfModule>
2. Apply the log format in the virtual host configuration file
[Email protected] ~]# vim/usr/local/apache2/conf/extra/httpd-vhosts.conf<virtualhost *:80> DocumentRoot "/data/www" ServerName www.test.com errorlog "Logs/test.com_error_log" Customlog "Logs/test.com_ Access_log "Combined # apply combined format log here </VirtualHost>
3. Reload the configuration file, visit the site and see if the log is generated
[Email protected] ~]#/usr/local/apache2/bin/apachectl-~]#/usr/local/apache2/bin/~]# ls/usr/ local/apache2/logs/ # generates the following two logs access_log error_log httpd.pid test.com_ Access_log test.com_error_log
Apache Configuration Access Log