把虛擬主機配置文件改爲以下:javascript
conf/extra/http-v ... <VirtualHost *:80> DocumentRoot "/data/wwwroot/ddd.com" ServerName ddd.com ServerAlias ttt.com eee.com www.example.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/ddd.com-access_log" combined env=!img </VirtualHost> ... bin/apachectl -t/graceful cd /data/wwwroot/ddd.com/ //在這目錄下上傳一個圖片
[root@axiang-02 apache2.4]# curl -x127.0.0.1:80 -I ddd.com/aming.png HTTP/1.1 200 OK tail /usr/local/apache2.4/logs/ddd.com-access_log [root@axiang-02 apache2.4]# tail /usr/local/apache2.4/logs/ddd.com-access_20170802.log 192.168.83.1 - - [02/Aug/2017:20:49:50 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36" 192.168.83.1 - - [02/Aug/2017:20:49:51 +0800] "GET / HTTP/1.1" 200 15 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36" 192.168.83.1 - - [02/Aug/2017:20:49:51 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "http://ddd.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36" 192.168.83.1 - - [02/Aug/2017:20:50:03 +0800] "GET /index.php HTTP/1.1" 200 15 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36" 192.168.83.1 - - [02/Aug/2017:20:50:12 +0800] "GET / HTTP/1.1" 200 15 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36" 192.168.83.1 - - [02/Aug/2017:20:50:22 +0800] "GET / HTTP/1.1" 200 15 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" 192.168.83.1 - - [02/Aug/2017:20:50:22 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "http://ddd.com/" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" 192.168.83.1 - - [02/Aug/2017:21:26:07 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36" 192.168.83.1 - - [02/Aug/2017:21:26:07 +0800] "GET /favicon.ico HTTP/1.1" 404 209 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36" 192.168.83.1 - - [02/Aug/2017:21:32:54 +0800] "GET /index.php HTTP/1.1" 200 15 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36" [root@axiang-02 apache2.4]#
能夠看到,沒有訪問png的記錄php
CustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/ddd.com-access_%Y%m%d.log 86400" combined env=!img
apache能夠設置緩存保存時間css
cd /usr/local/apache2.4/ vim 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 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> ... vim conf/httpd.conf /expires_module //開啓 bin/apachectl -M | grep expire bin/apachectl -t bin/apachectl graceful curl -x127.0.0.1:80 ddd.com/aming.png -I
如圖,cache-control: max-age爲緩存有效期html
apache日誌記錄代理IP以及真實客戶端IP http://www.lishiming.net/thread-960-1-1.htmljava
apache只記錄指定URI的日誌 http://www.lishiming.net/thread-981-1-1.htmlapache
apache日誌記錄客戶端請求的域名 http://www.lishiming.net/thread-1037-1-1.htmlvim
apache 日誌切割問題 http://www.lishiming.net/thread-566-1-1.html瀏覽器