Nginx限制搜索引擎爬蟲頻率、禁止屏蔽網(wǎng)絡爬蟲配置示例
#全局配置
limit_req_zone $anti_spider zone=anti_spider:10m rate=15r/m;
#某個server中
limit_req zone=anti_spider burst=30 nodelay;
if ($http_user_agent ~* "xxspider|xxbot") {
set $anti_spider $http_user_agent;
}
超過設置的限定頻率,就會給spider一個503。
上述配置詳細解釋請自行google下,具體的spider/bot名稱請自定義。
附:nginx中禁止屏蔽網(wǎng)絡爬蟲
server {
listen 80;
server_name www.xxx.com;
#charset koi8-r;
#access_log logs/host.access.log main;
#location / {
# root html;
# index index.html index.htm;
#}
if ($http_user_agent ~* "qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot") {
return 403;
}
location ~ ^/(.*)$ {
proxy_pass http://localhost:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
可以用 curl 測試一下
相關文章
nginx調用php-fpm出錯解決方法和nginx配置詳解
這篇文章介紹了nginx調用php-fpm出錯的解決方法,最后給出了nginx配置方法,需要的朋友可以參考下2014-03-03利用Nginx反向代理與負載均衡搭建多人測試環(huán)境詳解
這篇文章主要介紹了利用Nginx反向代理與負載均衡搭建多人測試環(huán)境的相關資料,文中介紹的非常詳細,相信對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。2017-04-04nginx實現(xiàn)根據(jù)URL轉發(fā)請求的實戰(zhàn)經(jīng)歷
這篇文章主要給大家介紹了一次關于nginx實現(xiàn)根據(jù)URL轉發(fā)請求的實戰(zhàn)經(jīng)歷,文中通過示例代碼介紹的非常詳細,對大家學習或者使用nginx具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-11-11nginx connect() to unix:/var/run/php-fpm.sock failed (11: Re
這篇文章主要介紹了nginx connect() to unix:/var/run/php-fpm.sock failed (11: Resource temporarily unavailable),需要的朋友可以參考下2015-01-01Docker Nginx容器和Tomcat容器實現(xiàn)負載均衡與動靜分離操作
這篇文章主要介紹了Docker Nginx容器和Tomcat容器實現(xiàn)負載均衡與動靜分離操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11