vlambda博客
学习文章列表

Nginx开启图片防盗链配置

由于服务器最近几天被入侵,在分析日志的时候发现很多盗链请求。所以顺手给Nginx加了个防盗链配置。
配置内容:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|bmp|swf|flv|mp3|wma)$ {

        expires max;

        log_not_found off;

        referer_hash_bucket_size 64;

        referer_hash_max_size 2048;

        valid_referers none blocked server_names

            *.biaodianfu.com

            *.sogoucdn.com

            *.baidu.com

            ~\.google\.;

        if ($invalid_referer) {

            rewrite ^/ http://img02.sogoucdn.com/v2/thumb/resize/zi/on/retype/ext/auto?appid=100140033&url=https://www.biaodianfu.com/wp-content/uploads/2019/11/bg_link.jpg;

            #return 403;}

    }

指令说明:
valid_referers [none | blocked | server_names]
  • none:refer头缺席被认为是有效的;
  • blocked:由防火墙伪装的referer被认为有效;如XXXXXX
  • server_names:被指定的名字被认为是有效的;


------------------------------------------------------------------

免责声明:本文内容转载自网络,其版权和著作权属于原作者。如果涉及侵权请尽快告知,我们将会在第一时间删除

原文链接:https://www.biaodianfu.com/nginx-image.html