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>

五、測試

當開啟防盜鏈時,訪問要盜用的服務器,圖片顯示不出來。

當把防盜鏈代碼注釋之后,訪問要盜用的服務器,圖片就可以顯示出來。

更多關于云服務器域名注冊,虛擬主機的問題,請訪問三五互聯官網:www.shinetop.cn

贊(0)
聲明:本網站發布的內容(圖片、視頻和文字)以原創、轉載和分享網絡內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。郵箱:3140448839@qq.com。本站原創內容未經允許不得轉載,或轉載時需注明出處:三五互聯知識庫 » Linux Centos7下實現nginx防盜鏈部署

登錄

找回密碼

注冊