NGINX 最基本的防爬虫、防盗链

 

防爬虫在 [ server内location外 ] 配置

if ($http_user_agent ~* (baiduspider|360spider|haosouspider|googlebot|soso|bing|sogou|yahoo|sohu-search|yodao|YoudaoBot|robozilla|msnbot|MJ12bot|NHN|Twiceler)) {
   
    return 403;
}

 

资源盗链配置在location内部

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

    root html

    valid_referers none blocked *.baidu.com;

    if ($invalid_referer) {
        rewrite ^/ 403.html
        #return 404;
    }
}

 

你可能感兴趣的:(Linux,NGINX)