Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I have an Apache server configured on a Debian 6.0 machine. I'm going to have a bunch of vhosts on this server and was wondering how to configure logrotate ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2012
    Posts
    44

    Apache vhost and logrotate


    Hi,

    I have an Apache server configured on a Debian 6.0 machine.
    I'm going to have a bunch of vhosts on this server and was wondering how to configure logrotate for them if I don't have the logs in the default folder.

    As of now I have it like this. Each vhost has it's own directory in /var/www/vhosts with some subdirs like this:


    /var/www/vhosts/example.com:
    -> cgi-bin
    -> html_doc
    -> logs


    So everyone can see their own logfiles.
    However as default Apache has all the logs in /var/log/apache2 and it rotate the logs just fine there and the logrotate conf for that looks like this:


    Code:
    /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
    }
    Is it possible to do it like this in my scenario?

    Code:
    /var/www/vhosts/*/logs/*.log {
            weekly
            missingok
            rotate 52
            compress
            delaycompress
            notifempty
            create 640 root adm
            sharedscripts
            postrotate
                    /etc/init.d/apache2 reload > /dev/null
            endscript
    }
    Or won't it accept two wildcards like that?


    Thanks,
    -Patric

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,423
    Afaik, logrotate accepts wildcards, even multiple times.

    Other than that, may I suggest an improvement to your setup?
    Logrotate would reload the apache for each rotated file, which is not ideal.

    With the help of an external tool (cronolog) and the ability of apache to write logs to pipes, this config snippet implements a non-interrupted logservice:

    Code:
    <Macro MyWebsite $country $serverdomain>
      <VirtualHost        *>
        ServerName	www.$serverdomain
    .
    .
        CustomLog "|| /usr/sbin/cronolog \
                   -S /data/log/apache/MyWebsite_$country_access.log \
                   /data/log/apache/MyWebsite_$country_access.log-%Y%m%d" \
                   combined
      </VirtualHost>
    </Macro>
    
    Use MyWebsite de myDEdomain
    Use MyWebsite fr myFRdomain
    Use MyWebsite uk myUKdomain
    Notes:
    - The || makes sure, that no extra shell is started. It is no longer needed in apache 2.4. A single | does the same.
    - mod_macro is used here. In case you wonder where $country comes from
    - /data/log/apache/MyWebsite_$country_access.log is a symlink. The name is static.
    - Rotated and the current logfiles have a timestamp in the name.
    - ErrorLog and AccessLog can of course also log to pipes.

    So essentially, apache rotates its own files in a non-service-interrupting way.
    They are not gzipped and old ones will not be deleted. This might or might not be an issue for you and probably a task for further processing.
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    Apr 2012
    Posts
    44
    Thanks, I will take a look at that!

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •