How to register page requests with Apache?

I host several documents on my local machine using Apache for my group. I copied / linked documents under /var/www/html .

Is there a way to record timestamped requests for each request?

+4
source share
4 answers

Logging should be turned on from the box and log into a file called access_log. I have never seen an installation where it has not yet been switched on.

Typically, the directive for where to register is set in the httpd.conf file. In most cases, the file is located in / var / log / apache2.

+7
source

Assuming your Apache server is running and you have shell access:

do the following:

 genja ~ # ps aux |grep apache|tail -n1 root 23605 0.0 0.2 248636 10684 ? Ss Jun08 0:06 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D LANGUAGE -D MANUAL -D SSL -D SSL_DEFAULT_VHOST -D PHP5 -D PERL -D PROXY -D SCGI -d /usr/lib64/apache2 -f /etc/apache2/httpd.conf -k start 

.. This is the daemon apache process. You are looking for "-f / etc / apache2 / http.conf". If your apache server was not told (according to distro init scripts) where to get the configuration file, it will look in the default location, which can be located under: / etc / apache2 / or /etc./httpd/ (or somewhere else, indeed, but these two are the most common). In this folder you will find a file called apache2.conf or httpd.conf
just try the following:

 find /etc/ -iname httpd.conf -o -iname apache2.conf 

Once you have installed the configuration file for the apache server, find the line where they include the module configurations. On my system, it looks like this:

 Include /etc/apache2/modules.d/*.conf 

Now you need to find out where the log file is:

 genja modules.d # grep CustomLog /etc/apache2/modules.d/* 00_mod_log_config.conf:# a CustomLog directive (see below). 00_mod_log_config.conf:CustomLog /var/log/apache2/access_log common 00_mod_log_config.conf:#CustomLog /var/log/apache2/referer_log referer 00_mod_log_config.conf:#CustomLog /var/log/apache2/agent_logs agent 00_mod_log_config.conf:#CustomLog /var/log/apache2/access_log combined 

which you are looking for: CustomLog / var / log / apache2 / access_log common.
Please note that this CustomLog directive may also be located in the main apache2.conf file.
You now have the location of the log file. Most likely, stopping your server from logging in now is file permissions. Make sure that the directory specified in the CustomLog section exists and that the Apache server can write to it:

as root:

 mkdir -p /var/log/apache2 touch /var/log/apache2/access_log chown -R APACHEUSER /var/log/apache2 chmod 755 /var/log/apache2 chmod 644 /var/apache2/access_log 

where APACHEUSER will most likely be apache or www or even httpd. You can understand this by doing:

 genja ~ # ps aux |grep apache |awk '{print $1}' apache (...) apache root 

So the user running the apache server on my system is actually called apache. This is not the root. Or at least it should not be.

restart your server after changing the resolution of this file. I do not know how your distribution does it. I think ubuntu has a [s] command. But you can always run the init script directly:

/etc/init.d/apache restart (ir may be located elsewhere on your distribution) just restart the entire computer if you do not know how to restart the Apache server.

If the access_log file is empty after restarting the server, replace APACHEUSER with root in the command above.

after that, just use your favorite pager or text editor to view the magazine. Or even the -f tail to control it in real time. Hope this helps. globigerin

+4
source

I can imagine that you created a virtual host (called vhost) for your / var / www / html document root. That way, you can simply add your logging requirements to this particular vhost, because you will get a specific log file.

Like this example:

 <VirtualHost *:80> DocumentRoot /var/www/html ServerName www.yourdomain.org ServerAdmin webmaster@domain.de <Directory "/var/www/html"> Options FollowSymLinks MultiViews AllowOverride all Order allow,deny Allow from all # if you need some users basic authentication # AuthType Basic # AuthName "MY DOMAIN AUTHENTICATION" # AuthUserFile ${APACHE_BASEDIR}/conf.d/special_users # Require user foobar </Directory> # your log specific requirements # LOGS (overwriting previous conf See /etc/apache2/apache2.conf) # Possible values for LogLevel : debug, info, notice, warn, error, crit, alert, emerg. LogLevel info ErrorLog /var/log/apache2/my_special_error.log # Option 1 (recommended): you merge these specific logs with the overall log file name and format # CustomLog /var/log/apache2/access.log combined # Or, Option 2: you set up a specific log file for that domain LogFormat "%h %l %u %t \"%r\" %>s %b" my_special_access.log CustomLog /var/log/apache2/my_special_access.log </VirtualHost> 

You will find a way to format the logs in the main apache configuration file, for example / etc / apache 2 / apache2.conf, in distributions like debian. Either you accept them as they are, or overwrite them in the virtual host configuration. If you do not work with virtual hosts, this does not change these principles.

You can then manipulate the access.log file to extract, analyze, copy, or do whatever you want. You can do this either in shell bash scripting (or perl, or even python or C or ...). I would recommend bash that you can easily automate as a cronjob.

+1
source
 LogFormat "%h %l %u %t \"%r\" %>s %b" mylog CustomLog logs/doc_root_access_log mylog 

which will be output as shown below (timestamp) to the doc_root_access_log log file

 127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 

You really should refer to here , as they have detailed explanations, especially in the log modifier.

0
source

Source: https://habr.com/ru/post/1343585/


All Articles