Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Help me create a Master Access Log |
|
Author |
|
FeelinGroovy
Joined: 05 Aug 2016 Posts: 2 Location: UK
|
Posted: Fri 05 Aug '16 15:23 Post subject: Help me create a Master Access Log |
|
|
Hello
I am not sure if this is the correct forum for this question, please excuse me if it is not?
I am running cloudlinux on Apache 2.4. I would like to be able to observe (watch) a "master" log of VirtualHost activity.
For example, in putty or e.g. in WHM via CSF at the moment, I am able to tail error_logs and others. Whilst this is useful, it does not really supply all relevent info on a visitor e.g. remote IP address, user agent of visitor, http page request, referrer etc. So I'd like to create a custom "master log" to log all such VH visitor traffic to a single log file.
Currently I have a number of virtualhosts in Apache 2.4 httpd file - each with their own logging directive. It is my understanding from Apache documentation that if a logging directive is placed outside the VH record, it will take precedence. Do I still need to create the custom log in each VH block?
I don't really want to overcomplicate this and have to combine logs and then split them etc. and I would still like each virtual host to log its own data. So I'm looking for an "easy" way to grab the required info and output it to a custom 'master' access log?
I realise I would need to enable log rotation for this new master log - and I also realise that such a "master" log could get very large quite quickly - so any helpful thoughts would be appreciated.
I've tried with the following logging directive, but I'm fairly new to Linux server management and not sure what I'm doing is right. I've added this at the top of httpd file, outside of VH block;
Code: |
<IfModule log_config_module>
# info from http://www.techstacks.com/howto/log-client-ip-and-xforwardedfor-ip-in-apache.html
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
CustomLog "logs/access_log" combined env=!forwarded
CustomLog "logs/access_log" proxy env=forwarded
</IfModule> |
Which results in this in the access_log
Code: |
::1 - - [05/Aug/2016:02:49:26 +1200] "OPTIONS * HTTP/1.0" 200 - "-" "Apache/2.4.23 (Unix) OpenSSL/1.0.1e-fips mod_bwlimited/1.4 (internal dummy connection)"`
|
I also tried various other suggested logging directives found on stackexchange and on here and in google, but so far I am not having any luck.
Please can someone assist?
Thank you in advance
Solace |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Wed 10 Aug '16 11:36 Post subject: |
|
|
you need to add the CustomLog to each vhost, but you can use the same config file of course. |
|
Back to top |
|
FeelinGroovy
Joined: 05 Aug 2016 Posts: 2 Location: UK
|
Posted: Wed 10 Aug '16 13:18 Post subject: |
|
|
I have many vhosts entries - I was hoping to find a way to not have to add it in manually!
I understand that I can use the template in cpanel to output to all vhosts - but I can't seem to get it to work!
Here's what I've done:
Copied /var/cpanel/templates/apache2_4/vhost.default to vhost.local and at the footer, right after this:
Code: |
[%- IF !added_include %]
[%- IF apache_target_version %]
[%- SET vhost_include_base = paths.dir_conf_userdata _ "/std/$apache_target_version/" %]
[%- ELSE %]
[%- SET vhost_include_base = paths.dir_conf_userdata _ '/std/2_4/' %]
[%- END %]
[%- domain = legacy_wildcard_safe(vhost.servername) %]
# To customize this VirtualHost use an include file at the following location
# Include "[% vhost_include_base %][% vhost.user %]/[% domain %]/*.conf"
[%- END %]
|
I have added this:
Code: |
<IfModule log_config_module>
LogFormat "%V %a %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\"" vcommon
CustomLog /usr/local/apache/logs/vhost-access_log vcommon
</IfModule>
</VirtualHost>
|
After doing the above I restarted Apache - but I don't see anything in httpd and no logs show up. Shouldn't the above add the log lines to httpd file in each vhost entry block? |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7373 Location: Germany, Next to Hamburg
|
Posted: Wed 10 Aug '16 15:09 Post subject: |
|
|
I never used cpanel. I don't know how your generated files look like now.
An easy way would be to use mod_macro. |
|
Back to top |
|
|
|
|
|
|