2018-04-16 Linux Learning

Source: Internet
Author: User
Tags auth exampl apache access log

11.21 Apache Access Log

Access log

访问日志记录用户的每一个请求vim /usr/local/apache2.4/conf/httpd.conf   //搜索 LogFormat    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined    LogFormat "%h %l %u %t \"%r\" %>s %b" common修改虚拟主机配置文件如下<VirtualHost *:80>    DocumentRoot "/data/wwwroot/111.com"    ServerName 111.com    ServerAlias www.exampl.com 2111.com.cn    ErrorLog "logs/111.com-error_log"    CustomLog "logs/111.com-access_log" common</VirtualHost>重新加载配置文件 -t , gracefulcurl -x127.0.0.1:80 -I 111.comtail /usr/local/apache2.4/logs/111.com-access_log

Operation Process

Last line common change to combined
[Email protected] ~]# vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<virtualhost *:80>
DocumentRoot "/data/wwwroot/111.com"
ServerName 111.com
Serveralias www.exampl.com 2111.com.cn
#<directory/data/wwwroot/111.com>

AllowOverride authconfig
    # authname "111.com user auth" # authtype Basic # authuserfile/data/.htpasswd # Require Valid-us Er #</directory> <ifmodule mod_rewrite.c> rewriteengine on Rewritecond%{http_host}!^111.co m$ rewriterule ^/(. *) $ http://111.com/$1 [r=301,l] </IfModule> errorlog "Logs/111.com-error_log" Cust Omlog "Logs/111.com-access_log" combined</virtualhost>[[email protected] ~]#/usr/local/apache2.4/bin/ Apachectl-tsyntax ok[[email protected] ~]#/usr/local/apache2.4/bin/apachectl graceful[[email protected] ~]# tail-5/usr/local/apache2.4/logs/111.com-access_log 192.168.106.160--[23/mar/2018:05:21:42 +0800] "GET http:// 111.com/dfafdjsaf http/1.1 "404 207192.168.106.1--[23/mar/2018:05:42:37 +0800]" get/http/1.1 "8"-"" Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) applewebkit/537.36 (khtml, like Gecko) chrome/65.0.3325.146 safari/537.36 "192.168.106.1--[23/ma r/2018:05:42:38 +0800] "get/faVicon.ico http/1.1 "404 209" http://111.com/"" mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) applewebkit/537.36 (khtml, like Gecko) chrome/65.0.3325.146 safari/537.36 "192.168.106.160--[23/ Mar/2018:05:43:35 +0800] "GET http://111.com/HTTP/1.1" 8 "-" "curl/7.29.0" 192.168.106.160--[23/mar/2018:05:43:42 + 0800] "HEAD http://111.com/HTTP/1.1"-"-" "curl/7.29.0"

11.22 The access log does not log static files (reduces the amount of memory that is not required to occupy storage space)

Access log does not record files of the specified type

网站大多数元素为静态文件,片、css、js等,这些元素可以不用记录把虚拟主机配置文件改成如下:<VirtualHost *:80>    DocumentRoot "/data/wwwroot/111.com"    ServerName 111.com    ServerAlias www.exampl.com 2111.com.cn    ErrorLog "logs/111.com-error_log"    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>重新加载配置文件 -t , gracefulmkdir /data/wwwroot/www.123.com/images   //创建目录,并在这目录下上传一个图片curl -x127.0.0.1:80 -I 111.com/images/123.jpgtail /usr/local/apache2.4/logs/111.com-access_log

Operation Process

Add setenvif several lines
[Email protected] ~]# vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<virtualhost *:80>
DocumentRoot "/data/wwwroot/111.com"
ServerName 111.com
Serveralias www.exampl.com 2111.com.cn
#<directory/data/wwwroot/111.com>

AllowOverride authconfig
#    AuthName "111.com user auth"#    AuthType Basic#    AuthUserFile /data/.htpasswd#    Require valid-user#</Directory><IfModule mod_rewrite.c>   RewriteEngine on   RewriteCond %{HTTP_HOST} !^111.com$   RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L]</IfModule>ErrorLog "logs/111.com-error_log"SetEnvIf Request_URI ".*\.gif$" imgSetEnvIf Request_URI ".*\.jpg$" imgSetEnvIf Request_URI ".*\.png$" imgSetEnvIf Request_URI ".*\.bmp$" imgSetEnvIf Request_URI ".*\.swf$" imgSetEnvIf Request_URI ".*\.js$" imgSetEnvIf Request_URI ".*\.css$" imgCustomLog "logs/111.com-access_log" combined env=!img

</virtualhost>

[[email protected] ~]# CP baidu.png/data/wwwroot/111.com/images/[[email protected] ~]# curl-x127.0.0.1:80 111.com111.test[[email protected] ~]# curl-x127.0.0.1:80 111.com111.test[[email protected] ~]# Curl- x127.0.0.1:80 111.com111.test[[email protected] ~]# curl-x127.0.0.1:80 111.com111.test[[email protected] ~]# curl-x127.0.0.1:80 111.com111.test[[email protected] ~]# curl-x127.0.0.1:80 111.com/images/baidu.png[[ Email protected] ~]# curl-x127.0.0.1:80 111.com/images/baidu.png[[email protected] ~]# curl-x127.0.0.1:80 111.com/images/baidu.png[[email protected] ~]# tail-5/usr/local/apache2.4/logs/111.com-access_log 127.0.0.1- -[23/mar/2018:06:26:25 +0800] "GET HTTP://111.com/HTTP/1.1" 8 "-" "curl/7.29.0" 127.0.0.1--[23/mar/2018:06:26:26 + 0800] "Get HTTP://111.com/HTTP/1.1" 8 "-" "curl/7.29.0" 127.0.0.1--[23/mar/2018:06:26:32 +0800] "Get HTTP://111.com /http/1.1 "8"-"curl/7.29.0" 127.0.0.1--[23/mar/2018:06:26:33 +0800] "Get HTTP://111.com/HTTP/1.1" 8 "-" "curl/7.29.0" 127.0.0.1--[23/mar/2018:06:26:33 +0800] "Get HTTP ://111.com/http/1.1 "8"-"curl/7.29.0"

11.23 Access Log Cutting

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.confCustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/111.com-access_%Y%m%d.log 86400" combined env=!img重新加载 -t , graceful

Operation Process

Modify Customlog
[Email protected] ~]# vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<virtualhost *:80>
DocumentRoot "/data/wwwroot/111.com"
ServerName 111.com
Serveralias www.exampl.com 2111.com.cn
#<directory/data/wwwroot/111.com>

AllowOverride authconfig
#   AuthName "111.com user auth"#   AuthType Basic#   AuthUserFile /data/.htpasswd#   Require valid-user#</Directory><IfModule mod_rewrite.c>   RewriteEngine on   RewriteCond %{HTTP_HOST} !^111.com$   RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L]</IfModule>ErrorLog "logs/111.com-error_log"SetEnvIf Request_URI ".*\.gif$" imgSetEnvIf Request_URI ".*\.jpg$" imgSetEnvIf Request_URI ".*\.png$" imgSetEnvIf Request_URI ".*\.bmp$" imgSetEnvIf Request_URI ".*\.swf$" imgSetEnvIf Request_URI ".*\.js$" imgSetEnvIf Request_URI ".*\.css$" imgCustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/111.com-access_%Y%m%d.log 86400" combined env=!img

</VirtualHost>

[[email protected] ~]# /usr/local/apache2.4/bin/apachectl -tSyntax OK[[email protected] ~]# /usr/local/apache2.4/bin/apachectl graceful[[email protected] ~]# curl -x127.0.0.1:80 111.com/123.png[[email protected] ~]# curl -x127.0.0.1:80 111.com/123.php[[email protected] ~]# ls /usr/local/apache2.4/logs/111.com-access_20180323.log

11.24 static element Expiration time

浏览器访问网站的图片时会把静态的文件缓存在本地电脑里,这样下次再访问时就不用去远程下载了增加配置,ExpiresActive on 打开功能开关

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

<IfModule mod_expires.c>    ExpiresActive on    ExpiresByType image/gif "access plus 1 days"    ExpiresByType image/jpeg "access plus 24 hours"    ExpiresByType image/png "access plus 24 hours"    ExpiresByType text/css "now plus 2 hours"    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>需要打开 expires_module 模块vim /usr/local/apache2.4/conf/httpd.confcurl 测试,看cache-control:max-age

Operation Process

Add ifmodule mod_expires.c segment
[[email protected] ~]# vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<virtualhost *:80>
DocumentRoot "/data/wwwroot/111.com"
ServerName 111.com
Serveralias www.exampl.com 111.com.cn
<ifmodule mod_expires.c>
expiresactive on
expiresbytype image/gif "Access Plus 1 days "
Expiresbytype image/jpeg" Access plus hours "
expiresbytype image/png" Access plus hours "
Expir Esbytype text/css "now plus 2 hours"
Expiresbytype application/x-javascript "now plus 2 hours"
Expiresbytype applic Ation/javascript "now plus 2 hours"
Expiresbytype Application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "Now plus 0 min"
</ifmodule>
errorlog "logs/111.com-error log"
Customlog "|/usr/local/apache2.4/ Bin/rotatelogs-l logs/111.com-access
%y%m%d.log 86400 "combined env=!img
</virtualhost>

Remove the # number in front of the module
[Email protected] ~]# vim/usr/local/apache2.4/conf/httpd.conf
LoadModule Expires_module modules/mod_expires.so

[[email protected] ~]# /usr/local/apache2.4/bin/apachectl -tSyntax OK[[email protected] ~]# /usr/local/apache2.4/bin/apachectl graceful[[email protected] ~]# curl -x127.0.0.1:80 111.com/images/baidu.png -IHTTP/1.1 200 OKDate: Fri, 23 Mar 2018 14:38:08 GMTServer: Apache/2.4.29 (Unix) PHP/5.6.34Last-Modified: Fri, 23 Mar 2018 06:14:50 GMTETag: "1ec5-5680e577a0a80"Accept-Ranges: bytesContent-Length: 7877Cache-Control: max-age=86400Expires: Sat, 24 Mar 2018 14:38:08 GMTContent-Type: image/png

2018-04-16 Linux Learning

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.