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、测试
Apache配置防盗链
盗链成功!!!
Apache配置防盗链
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、测试
图片不见了,盗链失败!!!
Apache配置防盗链
Apache配置防盗链