###修改添加配置
###参考:https://www.centos.bz/2018/01/nginx%E6%94%AF%E6%8C%81https%E5%B9%B6%E4%B8%94%E6%94%AF%E6%8C%81%E5%8F%8D%E7%88%AC%E8%99%AB/
vi /etc/nginx/anti_spider.conf
````
#禁止Scrapy等工具的抓取
if ($http_user_agent ~* (Python|Java|Wget|Scrapy|Curl|HttpClient|Spider)) {
return 403;
}
#禁止指定UA及UA为空的访问
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|Catall Spider|AcoiRobot") {
return 403;
}
if ($http_user_agent ~ "WinHttp|WebZIP|FetchURL|node-superagent|java/|FeedDemon|Jullo|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|Java|Feedly|Apache-HttpAsyncClient|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|HttpClient|MJ12bot|heritrix|EasouSpider|Ezooms|BOT/0.1|YandexBot|FlightDeckReports|Linguee Bot|iaskspider^$") {
return 403;
}
#禁止非GET|HEAD|POST方式的抓取
if ($request_method !~ ^(GET|HEAD|POST)$) {
return 403;
}
#屏蔽单个IP的命令是
#deny 123.45.6.7
#封整个段即从123.0.0.1到123.255.255.254的命令
#deny 123.0.0.0/8
#封IP段即从123.45.0.1到123.45.255.254的命令
#deny 124.45.0.0/16
#封IP段即从123.45.6.1到123.45.6.254的命令是
#deny 123.45.6.0/24
# 以下IP皆为流氓
#deny 58.95.66.0/24;
````
### 添加引导
````
server{
listen 80;
# 本地测试时可以将域名改为: 127.0.0.1
server_name www.lenggirl.com;
charset utf-8;
access_log /root/logs/nginx/www.lenggirl.com.log;
#error_log /data/logs/nginx/www.lenggirl.com.err;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://localhost:4000;
# 这个就是反爬虫文件了
include /etc/nginx/anti_spider.conf;
#
}
````
### 限制浏览器访问网站更目录下增加Robots.txt,放在站点根目录下
if ($http_user_agent ~* "Firefox|MSIE")
{
return 403;
}
- 第一章:Centos快捷操作
- EPEL 存储库
- 第二章:系统命令
- 第三章:Consul搭建配置
- consul-客户端配置win
- 第四章:Mongodb3.20搭建配置
- 1、mongodb-bak
- 第五章:Centos 7搭建Gitlab服务器
- yum-install
- 第六章:Mysql5.6主从搭建
- 第七张:Vmware-exsi6.5
- 第八章:Jumpserver 堡垒机
- 第九章:OCS Inventory NG-CMDB”
- 第十章:zabbix监控部署
- 第十一章:ELK快速搭建
- 第十二章:docker安装
- 第十三章:rabbitmq集群安装
- 第十四章:Nginx相关配置
- 1、Nginx禁止访问某个目录或某个后缀文件
- 2、Nginx-GeoIP部署
- 3、Nginx的lua-nginx-module模块
- 4、lua-resty-redis
- 5、nginx删除不安全的请求头
- 6、Nginx支持HTTPS并且支持反爬虫
- 7、nginx配置location总结及rewrite规则写法
- 7、nginx安装和监控
- 第十五章:racktables资产管理
- 第十六章:缓存服务安装
- memcache
- 第十七章:自动化管理
- ansible-playbook
- ansible-playbook-firewalld
- 第十八章:redis集群部署
- 第十九章:yapi配置ldap
- yapi
- 第二十章:winlogbeat
- win配置winlogbeat
