Apache: Difference between revisions

From vwiki
Jump to navigation Jump to search
(More typo)
(Added "Log Rotation")
Line 9: Line 9:
| <code> /etc/apache2 </code> || Config files
| <code> /etc/apache2 </code> || Config files
|}
|}
== Log Rotation ==
There are two ways to ensure your logs get rotated...
* logrotate - The standard, cross application log rotation solution.  Its very reliable and easy to configure, but requires that Apache is restarted every time your log is rotated so that it follows the log switch around.
* rotatelog pipe - Has more overhead as logs are piped to a child process to handle, but doesn't require Apache restarts.
=== rotatelog ===
Edit you existing config file to redirect logging through the child rotatelogs process, this will probably be found in either your site config (EG in <code>/etc/apache2/sites-enabled</code>) or your Apache service config (EG in <code> /etc/apache2/ </code>)
ErrorLog  "|/usr/sbin/rotatelogs /var/log/apache2/error-%Y-%m-%d.log 86400"
CustomLog "|/usr/sbin/rotatelogs /var/log/apache2/access-%Y-%m-%d.log 86400" combined
Check that the path for <code>rotatelogs</code> is correct (search using <code> find / -iname rotatelogs </code>)
Restart Apache, perform a test page load on your site (that would generate log entries), and check that a log file has been generated as per your config


== User/pass restrictions ==
== User/pass restrictions ==

Revision as of 11:12, 12 January 2012

File path What's there
/var/www Default web root
/var/log/apache Logs
/etc/apache2 Config files

Log Rotation

There are two ways to ensure your logs get rotated...

  • logrotate - The standard, cross application log rotation solution. Its very reliable and easy to configure, but requires that Apache is restarted every time your log is rotated so that it follows the log switch around.
  • rotatelog pipe - Has more overhead as logs are piped to a child process to handle, but doesn't require Apache restarts.

rotatelog

Edit you existing config file to redirect logging through the child rotatelogs process, this will probably be found in either your site config (EG in /etc/apache2/sites-enabled) or your Apache service config (EG in /etc/apache2/ )

ErrorLog  "|/usr/sbin/rotatelogs /var/log/apache2/error-%Y-%m-%d.log 86400"
CustomLog "|/usr/sbin/rotatelogs /var/log/apache2/access-%Y-%m-%d.log 86400" combined

Check that the path for rotatelogs is correct (search using find / -iname rotatelogs )

Restart Apache, perform a test page load on your site (that would generate log entries), and check that a log file has been generated as per your config

User/pass restrictions

  1. Create a user/pass entry in a file for a username
    • htpasswd -c /usr/local/apache2/conf/htusers username
  2. Add the relavent bits to the /etc/apache2/httpd.conf file, eg
    • <Directory />
    • AuthType Basic
    • AuthName "Restricted Access"
    • AuthUserFile /usr/local/apache2/conf/htusers
    • Require valid-user
    • </Directory>
  3. Restart the apache service
    • service apache2 restart