1. 程式人生 > 實用技巧 >Apache配置防盜鏈

Apache配置防盜鏈

1、準備2臺機器 192.168.234.136(yum安裝) 192.168.234.138(原始碼安裝)
以下在.136機器操作
#yum -y install httpd
#cd /var/www/html/
#ls
#vi index.html

heiheihei

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 httpd

2、測試

在這裡插入圖片描述
盜鏈成功!!!
在這裡插入圖片描述
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 //修改配置檔案

<VirtualHost :80>
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、測試
圖片不見了,盜鏈失敗!!!

在這裡插入圖片描述
在這裡插入圖片描述