nignx-防盗链

环境

 

主机                  IP            角色

centos6.5-1       192.168.3.10      源主机 

centos6.5-2       192.168.3.11      盗链接主机

 

一、分别在两台主机上搭建nginx

二、设置源主机

 

vim /usr/local/nginx/html/index.html

<head>

        <meta charset=utf-8>

</head>

<h1>源主机</h1>

<img src=a.jpg>

 

三、设置盗链主机

vim /usr/local/nginx/html/index.html

<head>

        <meta charset=utf-8>

</head>

<h1>盗链</h1>

<img src=http://192.168.3.10/a.jpg>

 

 

四、设置源主机

 

cd /usr/local/nginx/html/

touch error.jpg

vim nginx.conf

server {

        listen       80;

        server_name  www.benet.com;

location ~* \.(gif|jpg|png|swf|flv)$ {

    valid_referers none blocked *.benet.com benet.com ;

      if ($invalid_referer) {

      rewrite ^/ http://192.168.3.10/error.jpg;

      #return 403;

      }

    }

 

解释:

referers:

在http请求头部中有此项

说明此请求是从哪个链接请求(哪台主机)过来的。

在nginx日志中也有此选项记录

posted @ 2017-03-15 21:38  借风拥你  阅读(168)  评论(0)    收藏  举报