Linux9.9apache Log

Source: Internet
Author: User
Tags apache access log

Apache Access Log

View the virtual machine log file directory through the virtual host configuration Vhost file

Access logging for each user's request, in the HTTPD profile definition log format, is a virtual host profile that uses the format name to define the log format

vim/usr/local/apache2.4/conf/httpd.conf//Search Logformat Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{User- Agent}i\ "" Combined Logformat "%h%l%u%t \"%r\ "%>s%b" common h source IPU user T time R action Refere is a link into the site by a link User-agen T user access agent, such as browser, curl, etc. to change the virtual host configuration file as follows: <virtualhost *:80> documentroot "/data/wwwroot/111.com" ServerName 111 . com serveralias www.110.com customlog "Logs/123.com-access_log" combined</virtualhost> This is the virtual host log file after adding Common[[em Ail protected] extra]# cat/usr/local/apache2.4/logs/111.com-access_log 192.168.212.130--[04/mar/ 2018:01:11:00 +0800] "get/http/1.1" 7192.168.212.1--[04/mar/2018:04:20:04 +0800] "Get/favicon.ico http/1.1" 404 209192.168.212.1--[04/mar/2018:04:20:05 +0800] "Get/favicon.ico http/1.1" 404 209192.168.212.1--[04/MAR/2018:04:20: +0800] "get/http/1.1" 200 7 ... ...  192.168.212.130--[04/mar/2018:04:25:08 +0800] "get/http/1.1" 401 381192.168.212.130-chyuanliu [04/mar/2018:04:26:16 +0"get/http/1.1" 7127.0.0.1-chyuanliu [04/mar/2018:04:26:39 +0800] "GET HTTP://111.com http/1.1" 200 7192.168.2  12.1-chyuanliu [04/mar/2018:04:27:38 +0800] "get/http/1.1" 7192.168.212.1-chyuanliu [04/mar/2018:04:27:41 +0800] "Get/favicon.ico http/1.1" 404 209 plus combined after 192.168.212.1--[04/mar/2018:17:59:39 +0800] "Get/favicon.ico http/1.1" 301 238 "-" "mozilla/5.0 (Windows NT 6.1; WOW64) applewebkit/537.36 (khtml, like Gecko) chrome/53.0.2785.104 safari/537.36 core/1.53.4549.400 qqbrowser/ 9.7.12900.400 "
Access logs do not log static files

Most of the site elements are static files, tablets, CSS, JS, etc., these elements can not be recorded, can reduce access to log records

Modify the virtual host configuration file, enter it on the log output, define the environment variables

<virtualhost *:80>    documentroot "/data/wwwroot/www.111.com"    ServerName 111.com    serveralias  www.110.com    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     customlog "Logs/123.com-access_log" combined env=!img       #只要符合 img  , logs are not recorded </VirtualHost>

Experiment:

Create a. jpg end file in the/data/wwwroot/111.com directory, access the file through curl, and find that the log is not logged, stating that the configuration was successful.

Mkdir/data/wwwroot/www.123.com/images//Create a directory and upload a picture in this directory
Curl-x127.0.0.1:80-i 123.com/images/123.jpg
Tail/usr/local/apache2.4/logs/123.com-access_log

Access Log Cutting

Logs have been recorded one day will be full of the entire disk, so it is necessary to let it automatically cut, and delete the old log files
Change the Vhost virtual host configuration file to the following: Time 86400 is cut every day, automatically generate new log files every morning.
  
Customlog "|/usr/local/apache2.4/bin/rotatelogs-l logs/111.com-access_%y%m%d.log 86400" combined env=!img

Reload config file-T, graceful
Ls/usr/local/apache2.4/logs

static element Expiration Time

When a browser accesses a picture of a Web site, it caches the static files on the local computer so that it does not have to be downloaded remotely at the next visit.
Add configuration
<ifmodule mod_expires.c>
Expiresactive on//switch to turn on the function
Expiresbytype image/gif "Access plus 1 days"
Expiresbytype image/jpeg "Access plus hours"
Expiresbytype image/png "Access plus hours"
Expiresbytype text/css "Now plus 2 hour"
Expiresbytype Application/x-javascript "now plus 2 hours"
Expiresbytype Application/javascript "now plus 2 hours"
Expiresbytype Application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0 min"
</IfModule>
Need Expires_module
Curl test, see Cache-control:max-age

Linux9.9apache Log

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.