LAMP搭建12:Apache配置防盜鏈

來源:互聯網
上載者:User

標籤:lamp   apache   搭建   配置   防盜鏈   

為了防止別人盜用或者下載我們網站上的資源比片,音樂,視頻等等,佔用我們的頻寬,我們可以配置防盜鏈。

1.編輯虛擬機器主機設定檔:

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

2.加入如下內容:

……

<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 image/css "now plus 2 hours"

ExpiresByType application/x-javascript "now plus 2 hours"

ExpiresByType application/x-shockwave-flash "now plus 2 hours"

ExpiresDefault "now plus 0 min"

</IfModule>

SetEnvIfNoCase Referer "^http://.*\.test\.com" local_ref

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

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

       Order Allow,Deny

       Allow from env=local_ref

   </filesmatch>

<IfModule mod_rewrite.c>

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www.mydiscuz.com$ [OR]

RewriteCond %{HTTP_HOST} ^www.others.com$

RewriteRule ^/(.*)$ http://www.test.com/$1 [R=301,L]

</IfModule>

……

註:白名單中的網域名稱可以引用我們的資源,一定要將自己放入白名單!!!

3.檢查沒錯就重啟

[[email protected] logs]# apachectl -t

Syntax OK

[[email protected] logs]# apachectl graceful

現在未經授權的盜用都被禁止了。


LAMP搭建12: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.