Nginx的防盗链配置

 1 [[email protected] www]# cat /app/server/nginx/conf/vhosts/default.conf
 2 server {
 3     listen 80 default_server;
 4     server_name 192.168.1.24 web01.espressos.cn;
 5     root /app/www;
 6     index index.php index.html index.htm;
 7     location ~* \.(gif|jpg|png|swf|flv)$ { #对gif,jpg,png,swf,flv后缀的文件实行防盗链
 8     valid_referers none blocked 192.168.1.24 web01.espressos.cn; #对192.168.1.24 web01.espressos.cn这两个来路进行判断(主要是根椐http协议里的referer)
 9     if ($invalid_referer) { #if{}里面内容的意思是,如果来路不是指定来路就跳转到错误页面,当然直接返回403也是可以的。
10     rewrite ^/ http://192.168.1.24/403.html;
11     #return 404;
12     }
13     }
14     location ~ .*\.(php|php5)?$
15     {
16        #fastcgi_pass  unix:/tmp/php-cgi.sock;
17         fastcgi_pass  127.0.0.1:9000;
18     fastcgi_index index.php;
19     include fastcgi.conf;
20     }
21     access_log  /app/log/nginx/access/default.log;
22 }

验证代码:

[[email protected] www]# cat q.html
<html>
<body><img alt="http://192.168.1.24/cat.png" src="http://192.168.1.24/cat.png" height="auto" width="auto"></body>
</html>
[[email protected] www]# 

另一台WEB服务器盗用WEB01的图片(配置如下):

[[email protected] default]# cat /app/server/nginx/conf/vhosts/default.conf
server {
        listen       80;
        server_name  localhost;
    index index.html index.htm index.php;
    root /app/www/default;
    location ~ .*\.(php|php5)?$
    {
        #fastcgi_pass  unix:/tmp/php-cgi.sock;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires 30d;
    }
    location ~ .*\.(js|css)?$
    {
        expires 1h;
    }
    include /app/server/nginx/conf/rewrite/default.conf;
    access_log  /app/log/nginx/access/default.log;
}

验证:

[[email protected] default]# pwd
/app/www/default
[[email protected] default]# cat q.html
<html>
<body><img alt="http://192.168.1.24/cat.png" src="http://192.168.1.24/cat.png" height="auto" width="auto"></body>
</html>
[[email protected] default]# 

防盗成功!!!

把web01上的防盗代码注释掉:

[[email protected] www]# cat /app/server/nginx/conf/vhosts/default.conf
server {
    listen 80 default_server;
    server_name 192.168.1.24 web01.espressos.cn;
    root /app/www;
    index index.php index.html index.htm;
    #location ~* \.(gif|jpg|png|swf|flv)$ {
    #valid_referers none blocked 192.168.1.24 web01.espressos.cn;
    #if ($invalid_referer) {
    #    rewrite ^/ http://192.168.1.24/403.html;
    #    return 404;
    #    }
    #}
    location ~ .*\.(php|php5)?$
    {
       #fastcgi_pass  unix:/tmp/php-cgi.sock;
        fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include fastcgi.conf;
    }
    access_log  /app/log/nginx/access/default.log;
}
[[email protected] www]# /app/server/nginx/sbin/nginx -s reload

重新测式盗连图片的服务器,盗图是否成功:

图片盗连成功!!

时间: 2024-08-03 16:14:02

Nginx的防盗链配置的相关文章

nginx rewrite重写与防盗链配置

nginx rewrite重写规则与防盗链配置方法 时间:2016-02-04 15:16:58来源:网络 导读:nginx rewrite重写规则与防盗链配置方法,rewrite规则格式中flag标记的几种形式,盗链时返回403错误,允许的域名直接跟在第二行的域名后面. nginx rewrite重写规则与防盗链配置方法 nginx rewite 规则,官方文档:http://wiki.nginx.org/NginxHttpRewriteModule nginx rewrite规则格式:rew

Nginx的防盗链、Nginx的访问控制、Nginx解析php的配置、Nginx代理

Nginx的防盗链 Nginx的访问控制 禁止上传图片目录里php解析 Nginx解析php的配置 Nginx代理 原文地址:http://blog.51cto.com/13515599/2087315

Nginx系列-5.配置Nginx的防盗链

Nginx系列-5.配置Nginx的防盗链 目录 - Nginx系列 Nginx系列-1.Linux下安装Nginx Nginx系列-2.配置LNMP(Linux.Nginx.MySQL.PHP)架构 Nginx系列-3.配置Nginx虚拟主机 Nginx系列-4.Nginx日志配置及日志切割 Nginx系列-5.配置Nginx的防盗链 Nginx系列-6.配置Nginx的HTTPS Nginx系列-7.配置Nginx使用uwsgi支持web.py框架 Nginx系列-8.配置Nginx+Apa

NGINX 如何防盗链

一.安装Nginx:1.解决依赖关系 # yum groupinstall "Development Tools" "Server Platform Deveopment" # yum install openssl-devel pcre-devel 2.安装首先添加用户nginx,实现以之运行nginx服务进程: # groupadd -r nginx # useradd -r -g nginx nginx 接着开始编译和安装: # ./configure --p

Apache 防盗链配置

盗链 网站内有许多的图片地址,或一些我们可以用到的资源,在这种情况下,我可以通过赋值其他图片链接地址,到我自己的平台上,这样相当于盗取了一张图片的链接,那么盗链会有什么危害呢? 当我们盗取一张图片链接放入我们自己的平台时,我们每次访问平台也会连带 链接图片一起访问,要知道我们访问的图片是不在我们自己平台服务调去的资源,而是在获取链接图片的那台服务上边调用的,耗费的自然是它的资源请求,如果我们使用的平台访问量特别大,那会间接的导致盗取的链接服务一起被消耗资源,消耗带宽,所以为了避免这样的事情发生我

Nginx防盗链配置实例——从盗链模拟到防盗链设置流程细解

Nginx防盗链设置 ? 对于图片来说,A网站,如果想使用B网站的图片,可以直接写上B网站图片的链接地址,或者将B网站的图片通过右键另存为的方式下载到本地,然后在页面上使用.如果B网站不想A网站这么干了,那么B网站可以采取防盗链的措施来干这个工作,结果就是,A网站想请求所需要的资源,通过url的方式,获取的可能不是原来的图片了,出现404或者别的图片替代了.如果通过浏览器直接打开图片url,那么仍然有可能显示404,这就是防盗链. ? 下面我们先进行盗链的操作过程:就是如何做盗链网站--盗取别人

nginx 防盗链配置

防盗链分为两种:一种是url防盗链,一种是模块防盗链 1.url配置: valid_referers  none  blocked  server_names location ~*\.(jpg|png)$ {          valid_referers none  blocked 192.168.1.7;          if ($invalid_referer){               rewrite ^/ http://www.baidu.com;              #

配置Nginx实现防盗链功能!

准备两台Linux,用第二台linux主机来通过拿第一台主机的图片链接来展现图片: 因为主机2是通过主机1拿的图片链接所以当别人都通过链接访问图片时,占用的是主机一的内存空间,而不是占用主机2的内存空间 A)设定主机一为本公司的服务器,一旦非本公司人员通过链接去访问图片时,会对服务器造成内存压力. 解决方法,主机一做防盗链功能可以有效的阻止非本公司人员访问图片.以造成内存压力------->这样主机2将访问不到图片即使有图片链接 第一台Ip地址为:192.168.200.115 第二台ip地址值

Nginx下载防盗链(迅雷等下载软件)

什么是下载盗链   假设我们是一个B站,有些视频资源是可以提供给用户下载的.这时迅雷等其他下载软件,也提供下载该视频的服务, 但是迅雷很不厚道的,将我们的下载资源提供给他的用户,下载.占用我们的带宽来服务他的用户,这是绝对不可以忍了的. 使用来源判断根本不靠谱,只能防止一些小白站点的盗链,迅雷之类的下载工具完全无效,如果你是 nginx 的话,使用 secure link 完美解决这个问题,远离迅雷. 本文仅用于下载服务器,不适用于图片防盗链. 原理 用户访问 down.php down.php