獨立ip主機設置防盜鏈(適用vps云主機服務器)apache實現(xiàn)防盜鏈: 添加到.htaccess 文件中 RewriteCond %{HTTP_REFERER} !baidu.com [NC] RewriteCond %{HTTP_REFERER} !google.com [NC] RewriteCond %{HTTP_REFERER} !xxx.net [NC] RewriteRule .*\.(gif|jpg)$ /band.txt [NC,L] iis6實現(xiàn)防盜鏈:
進入others/httpd.conf中,保留前兩行,復制以下規(guī)則保存即可 RewriteEngine on RewriteCond %{HTTP_REFERER} !baidu.com [NC] RewriteCond %{HTTP_REFERER} !google.com [NC] RewriteCond %{HTTP_REFERER} !xxx.net [NC] RewriteRule .*\.(gif|jpg)$ /band.txt [NC,L] xxx.net是您自己的域名 band.txt是被盜鏈后的提示內容文件 iis7+實現(xiàn)防盜鏈: 使用url-rewrite模塊實現(xiàn),模塊下載地址 https://www.iis.net/downloads/microsoft/url-rewrite 在網站根目錄wwwroot下創(chuàng)建一個web.config文件,復制以下代碼保存即可, 如果網站有設置偽靜態(tài),已存在web.config,則只復制中間顏色部分代碼,加到第一個<rules>之后即可 <?xml version="1.0" ?> <configuration> <rule name="Prevent hotlinking"> <match url="^.*\.(rar|zip|jpg|gif)$" ignoreCase="true" /> <conditions> <add input="{HTTP_REFERER}" pattern="http://www.xxxxxx.com/.*" negate="true" /> <add input="{HTTP_REFERER}" pattern="http://xxxxxx.com/.*" negate="true" /> </conditions> <action type="Rewrite" url="/404.html" /> </rule> </rules> nginx實現(xiàn)防盜鏈: 參考添加靜態(tài)文件的location配置 server { listen 80; server_name www.yoursite.com; # 定位到圖片等靜態(tài)資源 location ~* \.(jpg|jpeg|png|gif|ico|css|js|pdf|mp4|mp3)$ { # 開啟防盜鏈功能 valid_referers none blocked server_names *.yoursite.com yoursite.com; # 判斷:如果 Referer 不在上面的合法值中,則返回 403 或重寫圖片 if ($invalid_referer) { return 403; # 或者重寫到一個防盜鏈提示圖片 # rewrite ^ /path/to/anti-stealing-image.jpg; } } }
|
|||||
| >> 相關文章 | |||||
|
|
|||||