Apache配置防盜鏈
阿新 • • 發佈:2020-10-09
1、準備2臺機器 192.168.234.136(yum安裝) 192.168.234.138(原始碼安裝)
以下在.136機器操作
#yum -y install httpd
#cd /var/www/html/
#ls
#vi index.html
test page
#vi /etc/hosts #vi /etc/hosts 192.168.234.138 www.test.com //新增另一臺機器的地址解析 #systemctl stop firewalld //關閉防火牆 #systemctl disable firewalld #setenforce 0 //關閉selinux #systemctl restart httpd2、測試
盜鏈成功!!!
2、配置防盜鏈
防止其他的網站大量使用自己網站裡的一些圖片,流量跑的是自己的網站,造成頻寬的浪費。防止圖片被盜用
在虛擬主機的配置檔案里加上:
SetEnvIfNoCase Referer “^http://.*.test.com” 1ocal_ref #給網址做標註
<filesmatch“\(txt|png|gif|doc|mp3|zip|rar|jpg|css|js)”> #規定一下哪些型別的檔案
order A11ow,Deny #禁止引用
Allow from env=local_ref #允許1ocal_ref引用
#vim /usr/local/apache2/conf/extra/httpd-vhosts.conf //修改配置檔案
DocumentRoot “/data/www”
ServerName www.test.com
SetEnvIfNoCase Referer "^http://..test.com" 1ocal_ref
<filesmatch “.(txt|png|gif|doc|mp3|zip|rar|jpg|css|js)”>
Order Allow,Deny
Allow from env=local_ref
#/usr/local/apache2/bin/apachectl restart //重啟服務
3、測試
圖片不見了,盜鏈失敗!!!