配置Apache日誌----防盜鏈

來源:互聯網
上載者:User

標籤:配置apache日誌----防盜鏈

Apache 不記錄指指檔案類型 

訪問 http://www.test.com/,在[[email protected] apache2]# cd /usr/local/apache2/logs/ 下有幾個記錄檔

[[email protected] logs]# ls

access_log  error_log  httpd.pid

現實環境中並不是所有的事件都需要記錄。所以我們需要自訂來解決這些問題。

前面是沒有修改前的 access_log

只截取一部分做樣本:

10.72.4.59 - - [23/Sep/2016:12:53:14 +0800] "GET /install/images/stepnum.gif HTTP/1.1" 304 -

10.72.4.59 - - [23/Sep/2016:12:53:14 +0800] "GET /install/images/bg_footer.gif HTTP/1.1" 304 -

10.72.4.59 - - [23/Sep/2016:12:53:14 +0800] "GET /install/images/bg_repx.gif HTTP/1.1" 304 -

10.72.4.59 - - [23/Sep/2016:12:53:14 +0800] "GET /install/images/bg_repno.gif HTTP/1.1" 304 -

修改進行時。。。。。。

[[email protected] logs]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>

   DocumentRoot "/tmp/123"

   ServerName 1111.com

</VirtualHost>


<VirtualHost *:80>

    DocumentRoot "/data/www"

    ServerName www.test.com

    ServerAlias www.aaa.com

    ServerAlias www.bbb.com


   ErrorLog "logs/www.test.com-error_log"

    SetEnvIf Request_URI ".*\.gif$" image-request

    SetEnvIf Request_URI ".*\.jpg$" image-request

    SetEnvIf Request_URI ".*\.png$" image-request

    SetEnvIf Request_URI ".*\.bmp$" image-request

    SetEnvIf Request_URI ".*\.mid$" image-request

    SetEnvIf Request_URI ".*\.mmf$" image-request

    SetEnvIf Request_URI ".*\.js$" image-request

    SetEnvIf Request_URI ".*\.css$" image-request

   CustomLog "|/usr/local/apache2/bin/rotatelogs -l /usr/local/apache2/logs/www.test.com-access_%Y%m%d_log 86400"  combined env=!image-request   #這裡是取反

[[email protected] logs]# apachectl -t  檢測一下文法有沒有問題

Syntax OK

重新整理網頁

[[email protected] logs]# ls

access_log  error_log  httpd.pid  www.test.com-access_20160926_log  www.test.com-error_log


[[email protected] logs]# less www.test.com-access_20160926_log 

10.72.4.59 - - [26/Sep/2016:23:13:11 +0800] "GET /forum.php HTTP/1.1" 200 12594 "-" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)"

10.72.4.59 - - [26/Sep/2016:23:13:13 +0800] "GET /home.php?mod=misc&ac=sendmail&rand=1474902791 HTTP/1.1" 200 - "http://www.test.com/forum.php" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)"


網站上的小圖片就不去記錄了,配置成功。

怎麼不去記錄一些靜態檔案的配置方法。2016-09-27 16:56

###########################################################################################
Apache 靜態緩衝配置

在日常的營運工作中有一些問題 。在訪問一個網站的時候會很多小圖片。這此圖片佔據了這個網頁很多的原素,佔用的空間也很大,將網頁的傳輸變小,可以將靜態檔案在瀏覽器這一側做緩衝。這個可以在Apache 這端可以配置的,規定在用戶端緩衝多久。這樣做可以節省很多的頻寬資源。

[[email protected] logs]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf

<IfModule mod_expires.c>    #模組名(靜態緩衝的配置模版)

ExpiresActive on

ExpiresByType image/gif "access plus 1 days"          #gif圖片緩衝1天

ExpiresByType image/jpeg "access plus 24 hours"       #jpeg緩衝1天

ExpiresByType image/png "access plus 24 hours"        #png緩衝1天

ExpiresByType text/css "now plus 2 hour"              #css緩衝2小時

ExpiresByType application/x-javascript "now plus 2 hours"        #緩衝2小時

ExpiresByType application/x-shockwave-flash "now plus 2 hours"        #緩衝2小時

ExpiresDefault "now plus 0 min"       #其餘不緩衝

</IfModule>


[[email protected] logs]# curl -x127.0.0.1:80 ‘http://www.test.com/static/image/common/logo.png‘ -I

650) this.width=650;" src="http://s1.51cto.com/wyfs02/M00/88/1F/wKioL1fqPRGAg6-IAAEQR9VKbso001.jpg-wh_500x0-wm_3-wmp_4-s_1618142675.jpg" title="dis17.jpg" alt="wKioL1fqPRGAg6-IAAEQR9VKbso001.jpg-wh_50" />

注意圖片中:

Cache-Control: max-age=86400  86400s 就是一天。


這就是靜態檔案快取配置。


分割線###############################################################################分割線


Apache 防盜鏈的配置

網站的圖片,flash ,mp3,等這些資源有可能被別人盜用

-------------------------------------------------------------------------

[[email protected] ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 


SetEnvIfNoCase Referer "^http://.*\.test\.com" local_ref #白名單 網域名稱不能出錯要不然圖片都不會顯示了

SetEnvIfNoCase Referer ".*\.aaa\.com" local_ref #白名單

<filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif)"> #設定的圖片格式

Require all denied

Require env local_ref 條件等於local_ref

------------------------------------------------------------------------------------------

[[email protected] ~]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf 

 SetEnvIfNoCase Referer "^http://.*\.1test\.com" local_ref  #此處如果改成其它的網域名稱

        SetEnvIfNoCase Referer ".*\.aaa\.com" local_ref

        <filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif|png)">

         #Order Allow,Deny

         #Allow Form env=local_ref

         Require all denied

         Require env local_ref

       </filesmatch>

(ps:目前apache版本是2.2,所以配置比2.4之後的版本有所不同舉一些例子。)

[[email protected] ~]# apachectl -t

Syntax OK

[[email protected] ~]# apachectl restart

再重新訪問網站就是下面的效果。圖片檔案&限的檔案均不顯示。

650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/88/2C/wKiom1fqnXPAncfvAAGvOliz75A446.jpg-wh_500x0-wm_3-wmp_4-s_2260166219.jpg" title="dis18.jpg" alt="wKiom1fqnXPAncfvAAGvOliz75A446.jpg-wh_50" />


做防盜鏈的時候一定要記得把自已的網站加進白明單,不然就會出現上面的效果。

本文出自 “CBO#Boy_Linux之路” 部落格,請務必保留此出處http://20151213start.blog.51cto.com/9472657/1857178

配置Apache日誌----防盜鏈

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.