標籤: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配置防盜鏈