nginx图片防盗链设置

location ~* \.(gif|jpg|png|jpeg)$ {
                expires     30d;
                valid_referers *.baidu.com;
                if ($invalid_referer) {
                        rewrite ^/ http://www.susanguitar.com/Home/Index/cdn;
                #return 404;
        }
        }


location ~* \.(gif|jpg|png)$ {
                expires     30d;
                valid_referers images.baidu.com;
                if ($invalid_referer) {
                        rewrite ^/ /not.jpeg;
                #return 404;
        }
        }

测试发现只允许百度,其它域名src就出现not.jpeg

if ($invalid_referer != 1) {

就变成只禁止百度

$invalid_referer只返回0或1

location ~* \.(gif|jpg|png)$ {
                expires     30d;
                valid_referers image.baidu.com;
                if ($invalid_referer != 1) {
                        rewrite ^/ /not.jpeg;
                #return 404;

        }
        }

多域名,允许空header

location ~ .*\.(gif|jpg|jpeg|png)${
                valid_referers  none blocke  *.aaa.cn *.bbb.com *.cccc.com;
                if ($http_shw_rq_test = 1){
                        set $invalid_referer 0  ;
                }
                if ($invalid_referer) {
                        return 403;
                }

        }

标签: nginx, 防盗链, linux安全配置

非特殊说明,本博所有文章均为博主原创。

最新文章

发表评论