location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|JPG|ico)$ {  
           expires      30d;
             access_log off;  
    }  
    location ~ .*\.(js|css)$ {  
        expires      1d;  
        access_log off;  
    }  
        access_log  logs/access_www.log  main ;
        error_log  logs/error_www.log;

简单的防盗链配置

location ~ .*\.(jpg|gif|png)${
   valid_referers none blocked 121.127.252.8;
   if($invalid_referer){
       retrun 403;
   }

}

valid_referers none blocked 121.127.252.8;这句话表示 允许那些http_referer过来 none 为空的 blocked表示不是http协议信息过来的,只允许121.127.252.8。通俗讲是一个规则匹配,如果valid_referers匹配成功 $invalid_referer为true;

valid_referers支持正则

Last modification:April 3, 2020
如果觉得我的文章对你有用,请随意赞赏