1、在網站發布目錄下編輯html文件并準備一張圖片名為33.jpg,這里網站發布目錄為/web1
vim /web1/index.html
<html>
<head>
<meta charset=utf-8>
<title>hostphoto.com</title>
</head>
<body>
<center><img src=33.jpg alt=fangxi width=1000px height=900px /></center>
</body>
</html>
2、編輯nginx子配置文件
location / {
root /web1;
index index.html index.htm;
valid_referers none blocked 192.168.16.150;
if ($invalid_referer) {
return 403;
}
}
? none : 允許沒有http_refer的請求訪問資源;
? blocked : 允許不是http://開頭的,不帶協議的請求訪問資源—被防火墻過濾掉的;
? server_names : 只允許指定ip/域名來的請求訪問資源(白名單);
3、檢查配置文件是否有錯誤,沒有錯誤重新加載。
nginx -t
nginx -s reload
四、配置要盜用的服務器
1、配置nginx訪問頁面并創建目錄
location / {
root /web1;
index index.html index.htm;
}
mkdir /web1
2、創建頁面
vim /web1/index.html
<html>
<body >
<img src=https://cache.yisu.com/upload/information/20200309/28/29438.jpg />
</body>
</html>
五、測試
當開啟防盜鏈時,訪問要盜用的服務器,圖片顯示不出來。
當把防盜鏈代碼注釋之后,訪問要盜用的服務器,圖片就可以顯示出來。
更多關于云服務器,域名注冊,虛擬主機的問題,請訪問三五互聯官網:m.shinetop.cn