Nginx作為靜態資源web服務_防盜鏈配置
阿新 • • 發佈:2018-12-17
Nginx作為靜態資源web服務_防盜鏈配置
1、新建http_referer.html檔案
(1)touch http_referer.html
(2)編輯http_referer.html檔案
http_referer.html程式碼:
<html>
<head>http_referer test</head>
<body>
<h1>Welcome to http_referer!!!!</h1>
<image src="http://193.112.108.135/dragon.jpg"/>
</body>
</html>
2、發起http://193.112.108.135/http_referer.html請求
(1)瀏覽器發起請求
(2)Linux伺服器下模擬發起請求
curl http://193.112.108.135/http_referer.html
(3)檢視nginx access.log日誌檔案
訪問"GET /dragon.jpg HTTP/1.1"請求
$http_referer = "http://193.112.108.135/http_referer.html"
3、nginx增加防盜鏈配置
如果訪問ip不是193.112.108.135就會出現403 Forbidden報錯提示
4、驗證防盜鏈配置是否生效
(1)瀏覽器驗證
使用ip=193.112.108.135訪問正常:
使用域名dragonbrother.1.com訪問報錯:
(2)Linux伺服器下驗證
使用ip=193.112.108.135訪問正常:
使用別人的域名www.baidu.com域名訪問報錯:(說明不允許其他網站盜用自己網站資源)
使用自己的域名dragonbrother.1.com訪問報錯:
(3)允許其他網站訪問自己網站資源配置
允許www.baidu.com訪問我的圖片資源
允許http://nginx.org/訪問我的圖片資源
允許https://translate.google.cn/訪問我的圖片資源