真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

11.22訪問日志不記錄靜態(tài)文件

訪問日志不記錄指定類型的文件目錄概要 網(wǎng)站大多元素為靜態(tài)文件,如圖片、css、js等,這些元素可以不用記錄 把虛擬主機(jī)配置文件改成如下:

DocumentRoot "/data/wwwroot/www.123.com" ServerName www.123.com ServerAlias 123.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 重新加載配置文件 -t, graceful mkdir /data/wwwroot/www.123.com/images //創(chuàng)建目錄,并在這目錄下上傳一個圖片 curl -x127.0.0.1:80 -I 123.com/images/123.jpg tail /usr/local/apache2.4/logs/123.com-access_log 訪問日志不記錄指定類型的文件

創(chuàng)新互聯(lián)服務(wù)項目包括奉新網(wǎng)站建設(shè)、奉新網(wǎng)站制作、奉新網(wǎng)頁制作以及奉新網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,奉新網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到奉新省份的部分城市,未來相信會繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

瀏覽器可以查看到頁面元素,按 F12 查看頁面元素內(nèi)容,它默認(rèn)定位在Network。如果不是在Network,就去選擇下Network,然后刷新下網(wǎng)頁,會看到如圖

會看到右側(cè)出現(xiàn)很多的元素,每一行都表示一個元素,這些請求,這些訪問都會記錄到訪問日志里面去的,但實際上沒有必須記錄一些圖片、css、js等元素,而這些請求都會記錄到日志文件里,就會導(dǎo)致每天的日志訪問量很大,對之后的運(yùn)維很不方便,所以就有了需求,對于靜態(tài)的元素的uri 不進(jìn)行記錄

排除圖片、css、js等,拷貝配置文件到服務(wù)器里面

需要拷貝的配置文件

DocumentRoot "/data/wwwroot/www.123.com" ServerName www.123.com ServerAlias 123.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 打開虛擬主機(jī)配置文件 vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf 未更改前

DocumentRoot "/data/wwwroot/abc.com" ServerName abc.com ServerAlias www.abc.com www.123.com ErrorLog "logs/abc.com-error_log" CustomLog "logs/abc.com-access_log" common DocumentRoot "/data/wwwroot/111.com" ServerName 111.com ServerAlias www.example.com 2111.com.cn # # # AllowOverride AuthConfig # AuthName "111.com user auth" # AuthType Basic # AuthUserFile /data/.htpasswd # require valid-user # # RewriteEngine on RewriteCond %{HTTP_HOST} !^111.com$ RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L] ErrorLog "logs/111.com-error_log" CustomLog "logs/111.com-access_log" combined 更改后的配置文件,在 ErrorLog 下一行插入

[root@hf-01 ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf DocumentRoot "/data/wwwroot/abc.com" ServerName abc.com ServerAlias www.abc.com www.123.com ErrorLog "logs/abc.com-error_log" CustomLog "logs/abc.com-access_log" common DocumentRoot "/data/wwwroot/111.com" ServerName 111.com ServerAlias www.example.com 2111.com.cn # # # AllowOverride AuthConfig # AuthName "111.com user auth" # AuthType Basic # AuthUserFile /data/.htpasswd # require valid-user # # RewriteEngine on RewriteCond %{HTTP_HOST} !^111.com$ RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L] 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 并保存退出 相當(dāng)于定義了一個環(huán)境 img 是一個標(biāo)簽、一個變量,可以自定義,可以是任意字符 定義”..gif$”、”..jpg$”、”..png$”、”..bmp$”、”..swf$”、”..js$”、”.*.css$”;這些都是 img env=!img 表示 env非 img 類型的都進(jìn)行日志記錄 在設(shè)置好配置文件后,先不加載配置文件,先做一個測驗

[root@hf-01 ~]# curl -x127.0.0.1:80 111.com/asdasdsaf.jpg -I HTTP/1.1 404 Not Found Date: Thu, 21 Dec 2017 15:35:14 GMT Server: Apache/2.4.29 (Unix) PHP/7.1.6 Content-Type: text/html; charset=iso-8859-1 [root@hf-01 ~]# 在訪問這樣的請求,不管是404,還是200都會記錄日志

[root@hf-01 ~]# !tail tail -5 /usr/local/apache2.4/logs/111.com-access_log 192.168.202.130 - - [21/Dec/2017:21:51:25 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0" 192.168.202.1 - - [21/Dec/2017:21:51:32 +0800] "GET /123.php HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0" 192.168.202.130 - - [21/Dec/2017:21:55:08 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0" 192.168.202.1 - - [21/Dec/2017:22:04:27 +0800] "GET /123.php HTTP/1.1" 200 7 "http://ask.apelearn.com/question/17687" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0" 127.0.0.1 - - [21/Dec/2017:23:35:14 +0800] "HEAD HTTP://111.com/asdasdsaf.jpg HTTP/1.1" 404 - "-" "curl/7.29.0" [root@hf-01 ~]# 然后在檢查配置文件語法,并重新加載配置文件

[root@hf-01 ~]# /usr/local/apache2.4/bin/apachectl -t Syntax OK [root@hf-01 ~]# /usr/local/apache2.4/bin/apachectl graceful [root@hf-01 ~]# 這時再來curl訪問,會發(fā)現(xiàn)日志中沒有記錄

[root@hf-01 ~]# curl -x127.0.0.1:80 111.com/asdasdsaf.jpg -I HTTP/1.1 404 Not Found Date: Thu, 21 Dec 2017 15:39:35 GMT Server: Apache/2.4.29 (Unix) PHP/7.1.6 Content-Type: text/html; charset=iso-8859-1 [root@hf-01 ~]# tail -5 /usr/local/apache2.4/logs/111.com-access_log 192.168.202.130 - - [21/Dec/2017:21:51:25 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0" 192.168.202.1 - - [21/Dec/2017:21:51:32 +0800] "GET /123.php HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0" 192.168.202.130 - - [21/Dec/2017:21:55:08 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0" 192.168.202.1 - - [21/Dec/2017:22:04:27 +0800] "GET /123.php HTTP/1.1" 200 7 "http://ask.apelearn.com/question/17687" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0" 127.0.0.1 - - [21/Dec/2017:23:35:14 +0800] "HEAD HTTP://111.com/asdasdsaf.jpg HTTP/1.1" 404 - "-" "curl/7.29.0" [root@hf-01 ~]# 只要是gif、jpg、png、bmp、swf、js的都不會在日志中有記錄 本地上傳圖片并訪問 進(jìn)入到在/data/wwwroot/111.com目錄下

[root@hf-01 ~]# cd /data/wwwroot/111.com [root@hf-01 111.com]# ls 123.php index.php 并上傳一張圖片到該目錄下

[root@hf-01 111.com]# rz [root@hf-01 111.com]# ls 123.php index.php QQ111.jpg [root@hf-01 111.com]# 用curl命令查看圖片,會發(fā)現(xiàn)圖片是能訪問的

[root@hf-01 111.com]# curl -x127.0.0.1:80 111.com/QQ111.jpg -I HTTP/1.1 200 OK Date: Thu, 21 Dec 2017 15:50:24 GMT Server: Apache/2.4.29 (Unix) PHP/7.1.6 Last-Modified: Mon, 04 Dec 2017 03:56:48 GMT ETag: "da7f-55f7bb520e000" Accept-Ranges: bytes Content-Length: 55935 Content-Type: image/jpeg [root@hf-01 111.com]# 在瀏覽器訪問網(wǎng)頁圖片,會發(fā)現(xiàn)圖片是能訪問的

查看日志文件,會發(fā)現(xiàn)日志文件中沒有記錄圖片的日志,這個就是因為定義了日志標(biāo)簽

[root@hf-01 111.com]# tail -5 /usr/local/apache2.4/logs/111.com-access_log 192.168.202.130 - - [21/Dec/2017:21:51:25 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0" 192.168.202.1 - - [21/Dec/2017:21:51:32 +0800] "GET /123.php HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0" 192.168.202.130 - - [21/Dec/2017:21:55:08 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0" 192.168.202.1 - - [21/Dec/2017:22:04:27 +0800] "GET /123.php HTTP/1.1" 200 7 "http://ask.apelearn.com/question/17687" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0" 127.0.0.1 - - [21/Dec/2017:23:35:14 +0800] "HEAD HTTP://111.com/asdasdsaf.jpg HTTP/1.1" 404 - "-" "curl/7.29.0" [root@hf-01 111.com]# 這時去掉虛擬主機(jī)配置文件中的env=!img ,在用瀏覽器瀏覽圖片,在curl命令訪問圖片

[root@hf-01 111.com]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf 更改后 DocumentRoot "/data/wwwroot/abc.com" ServerName abc.com ServerAlias www.abc.com www.123.com ErrorLog "logs/abc.com-error_log" CustomLog "logs/abc.com-access_log" common DocumentRoot "/data/wwwroot/111.com" ServerName 111.com ServerAlias www.example.com 2111.com.cn # # # AllowOverride AuthConfig # AuthName "111.com user auth" # AuthType Basic # AuthUserFile /data/.htpasswd # require valid-user # # RewriteEngine on RewriteCond %{HTTP_HOST} !^111.com$ RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L] 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 這時再來刷新瀏覽器訪問圖片,用curl訪問圖片

[root@hf-01 111.com]# curl -x127.0.0.1:80 111.com/QQ111.jpg -I HTTP/1.1 200 OK Date: Thu, 21 Dec 2017 16:02:57 GMT Server: Apache/2.4.29 (Unix) PHP/7.1.6 Last-Modified: Mon, 04 Dec 2017 03:56:48 GMT ETag: "da7f-55f7bb520e000" Accept-Ranges: bytes Content-Length: 55935 Content-Type: image/jpeg [root@hf-01 111.com]# 查看日志文件,會發(fā)現(xiàn)日志文件有記錄存在

[root@hf-01 111.com]# tail -5 /usr/local/apache2.4/logs/111.com-access_log 192.168.202.130 - - [21/Dec/2017:21:51:25 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0" 192.168.202.1 - - [21/Dec/2017:21:51:32 +0800] "GET /123.php HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0" 192.168.202.130 - - [21/Dec/2017:21:55:08 +0800] "HEAD http://111.com/123.php HTTP/1.1" 200 - "-" "curl/7.29.0" 192.168.202.1 - - [21/Dec/2017:22:04:27 +0800] "GET /123.php HTTP/1.1" 200 7 "http://ask.apelearn.com/question/17687" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0" 127.0.0.1 - - [21/Dec/2017:23:35:14 +0800] "HEAD HTTP://111.com/asdasdsaf.jpg HTTP/1.1" 404 - "-" "curl/7.29.0" [root@hf-01 111.com]# 這時在到虛擬主機(jī)配置文件中加上env=!img ,并重新加載配置文件,在刷新圖片,會看到日志文件中并沒有記錄日志 日志文件不記錄總結(jié) 若是不去做一個限制,那么每一次請求都會記錄到日志文件,日志文件就會變得越來越大,這樣不僅會消耗磁盤空間,還會耗費(fèi)磁盤i/o,而且這些文件毫無意義,所以需要做一個限制


本文標(biāo)題:11.22訪問日志不記錄靜態(tài)文件
本文地址:http://weahome.cn/article/cjsojh.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部