Linux centos7 VMware Apache access logs do not log static files, access log cuts, static element expiration times

Source: Internet
Author: User
Tags curl

One, Apache 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

vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf//Change to the following

Change the virtual host configuration file to the following:

<virtualhost *:80>

DocumentRoot "/data/wwwroot/www.123.com"

ServerName www.111.com

Serveralias 111.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/111.com-access_log" combined env=!img

</VirtualHost>

Reload config file-T, graceful

Mkdir/data/wwwroot/www.111.com/images//Create a directory and upload a picture in this directory

Curl-x127.0.0.1:80-i 111.com/images/123.jpg

Tail/usr/local/apache2.4/logs/111.com-access_log

Second, 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 virtual host configuration file to the following:

Vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf

<virtualhost *:80>

DocumentRoot "/data/wwwroot/www.111.com"

ServerName www.111.com

Serveralias 111.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 "|/usr/local/apache2.4/bin/rotatelogs-l logs/111.com-access_%y%m%d.log 86400" combined env=!img

</VirtualHost>

Reload config file-T, graceful

Ls/usr/local/apache2.4/logs

Third, 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

Linux centos7 VMware Apache access logs do not log static files, access log cuts, static element expiration times

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.