Apache优化之---防盗链

注:Apache优化全程使用yum 安装httpd

何为防盗链,如
源网站 www.aaa.com 内有一个图片地址为 www.aaa.com/1.jpg
盗链网 www.bbb.com 发布文章时盗用 www.aaa.com/1.jpg 图片及被盗走使用(可能被盗走做非法行为,)所以我们使用防盗链技术使我们的图片不允许别的网站引用。接下来实操

环境
node1 源站 192.168.10.102
noide2 盗图站 192.168.10.103
都部署出httpd
源站代码

test

Apache优化之---防盗链 ![](https://www.icode9.com/i/l/?n=20&i=blog/2222036/202105/2222036-20210515213639234-640635017.png)

盗图站

test

Apache优化之---防盗链 ![](https://www.icode9.com/i/l/?n=20&i=blog/2222036/202105/2222036-20210515213407030-1471315429.png)

没有配置防盗链时可以轻松盗走我们的图片
此时我们开始配置防盗链
通过地址重写的方式来阻止网站图片被盗用
我们需要rewrite地址重写模块
Apache优化之---防盗链

有此模块我们可以直接去写防盗链配置
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://192.168.10.102/.$ [NC]
RewriteCond %{HTTP_REFERER} !^http://192.168.10.102/$ [NC]
RewriteCond %{HTTP_REFERER} !^http://192.168.10.102/.
$ [NC]
RewriteCond %{HTTP_REFERER} !^http://192.168.10.102/$ [NC]
RewriteRule .*.(gif|jpg|swf)$ http://192.168.10.102/error.png //图片被盗用后显示的图
Apache优化之---防盗链

完成之后检查apache并重启apache
进行测试
Apache优化之---防盗链

源站没有影响
Apache优化之---防盗链

盗图站的图片则不能被加载,此时防盗链则生效。

上一篇:【ubuntu 18.04】docker安装phabricator


下一篇:ThinkPHP报错 The requested URL /admin/index/login.html was not found on this server.