Apache access logs, access logs do not log static files, access log cuts

Source: Internet
Author: User
Tags apache access log

1. Apache Access Log

Enter command cat/usr/local/apache2.4/conf/extra/httpd-vhosts.conf, enter, see,

The access log for this virtual machine is inside the/logs/111.com-access_log, enter the command ls/usr/local/apache2.4/logs/, you can see the access log file, see,

You can use the command Cat/usr/local/apache2.4/logs/111.com-access_log to view the contents, enter, see,

The log displayed here is too simple to see any important information, you can define the format of the log, open the main configuration file, input command vim/usr/local/apache2.4/conf/httpd.conf, enter, search/logformat, see,

Logformat followed by the format of the log, the white word behind the common is the default format. The user-agent of the previous line is the user agent's meaning, such as browser and curl. Referer indicates that the last visited URL was recorded on the browser. Now change the virtual host profile, input: q!, enter, force exit interface. Enter command vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf, enter, see,

Change the contents of the red box to combined, save and exit. Then proceed down,

Then use the browser to access the 111.com/123.php, see,

Then go back to Putty, enter the command Cat/usr/local/apache2.4/logs/111.com-access_log, see the last few lines, see,

Significantly richer than before.

2. The access log does not record static files

Now login to a website, press F12 (Laptop press fn+f12), the right side will appear an interface, see,

Select the Network page, then refresh the page, you can see the interface,

You can see that you are accessing a Web site, but there are a lot of things loaded. Each row represents an element, and these requests and accesses are recorded in the Access log. Put the mouse on the line item to display an address, click to see the address, see,

This address is a request that will be recorded in the Access log. If each article is recorded in the log, the resulting content will be very much, the memory is very large, this is obviously unreasonable. So need to change the configuration file, the picture, CSS, JS and other content excluded, do not record. Next change the virtual host configuration file, enter the command vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf, carriage return, see,

In the red box position, insert the following:
Setenvif Request_uri ".. gif$ "img
Setenvif Request_uri ".
. jpg$ "img
Setenvif Request_uri ".. png$ "img
Setenvif Request_uri ".
. bmp$ "img
Setenvif Request_uri ".. swf$ "img
Setenvif Request_uri ".
. js$ "img
Setenvif Request_uri ". *.css$" img
After the following sentence, add env=!img, save and exit. "" "The contents of the double quotation mark are regular expressions, the following img is the tag, env=!img means that the content marked as IMG is not recorded.
This way do not reload the configuration file, that is, the content just changed temporarily does not take effect, first do an experiment, input command curl-x127.0.0.1:80 111.com/aghjkk.jpg-i, enter, see,

Aghjkk.jpg is a file that does not exist and is filled in randomly. When viewing the log, you can also see this JPG record. Then reload the provisioning profile, see,

To check JPG and PNG, whether there is a record, the specific operation see,



As you can see, jpg5 have records, JPG and PNG are not recorded.
Pictures using putty upload more trouble, this side does not show.
Use the command vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf, enter, see,

These characters will be env=!img, deleted, saved and exited. Reload the configuration file, then access JPG, PNG, see,


You can see the deletion of env=!img, access to JPG, PNG will be recorded. After verifying this, add the env=!img, and this side does not show.
It is important to note that the name IMG is optional and Lys is also available.

3. Access Log Cutting

Enter command vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf, enter, see,

Change the contents of the red box, save and exit. Rotatelogs is Apache's own cutting tool, and-L is based on the current system time (CST) and does not specify-l to cut the log in UTC time. Define the name of the log again,%y%m%d the date. Then define the cut time, usually one day, converted into seconds is 86400.
Reload the configuration file, see,

Now there is no log generation, to do some access, you can see the access log, see,

You can see the access log, which is the one you just visited. Then verify, see,

Now the log is a daily, but also need to make a plan, more than one months or two months of the log deleted, so as not to occupy space, and make the log cut meaningful, find the time is also very convenient.

Apache access logs, access logs do not log static files, access log cuts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.