Nginx負載均衡和防爬蟲策略

Nginx負載均衡和防爬蟲策略

vim langba888.conf
upstream langba888 {
#每60s進行一次健康檢測,檢測2次失敗,則進行剔除
server 192.168.137.52:888 max_fails=2 fail_timeout=60s;
server 192.168.137.48:888 max_fails=2 fail_timeout=60s;
}
server {
listen 9999;
#防止爬蟲策略
if ($http_user_agent ~* "WordPress") {
return 502;
}html

if ($http_user_agent ~* "spider") {
        return 502;
}

location / {
    proxy_pass         http://langba888;   #反向代理
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
}
error_page  404 403        /40x.html;
location = /40x.html {
        root   /usr/share/nginx/html;
}

error_page   500 502 503 504  /50x.html;
location = /50x.html {
        root   /usr/share/nginx/html;
}

}nginx

相關文章
相關標籤/搜索