源主机:
vim /etc/hosts
192.168.1.10 www.aaa.com
192.168.1.11 www.bbb.com
把图片放到/usr/local/nginx/html/
并给予权限
chmod 777 1.jpg
chmod 777 2.gif
vim /usr/local/nginx/conf/nginx.conf
添加以下内容:
location ~* \.(jpg|jpeg)$ {
valid_referers *.aaa.com aaa.com;
if ($invalid_referer) {
rewrite ^/ http://www.aaa.com/2.gif;
}
}
加到}后面
想让网页识别中文把这个注释去掉,并改为utf-8
charset utf-8;
验证
nginx -t
重启服务
systemctl restart nginx
盗链服务器:
vim /etc/hosts
192.168.1.10 www.aaa.com
192.168.1.11 www.bbb.com
vim /usr/local/nginx/html/index.html
添加以下内容:
<!DOCTYPE html>
<html>
<head>
<title>爬</title>
</head>
<body>
<h1>爬</h1>
<img src="http://192.168.1.10/1.jpg"
</body>
</html>
客户端验证一下