访问控制4/5
好比我想让谁访问个人网站,我就告诉他域名,若是不告诉别人域名,就说明我不想让他知道个人站点,这须要禁止搜索引擎在网络上爬取站点内容。能够经过user_agent来限制。html
编辑虚拟主机文件nginx
[root[@localhost](https://my.oschina.net/u/570656) ~]# vim /usr/local/nginx/conf/vhost/test.com.conf
添加以下内容vim
if ($http_user_agent ~* 'Spider/3.0|baidu|YoudaoBot|Tomato') { return 403; }
测试并从新加载配置文件 ..-t ...-s reload网络
使用curl测试,curl -A 能够模拟user_agent,发现返回的代码是403,表示实验成功。curl
[root[@localhost](https://my.oschina.net/u/570656) ~]# curl -A "www.baidu.com" -x127.0.0.1:80 test.com -I HTTP/1.1 403 Forbidden Server: nginx/1.15.3 Date: Tue, 04 Sep 2018 17:57:37 GMT Content-Type: text/html Content-Length: 169 Connection: keep-alive
什么是URI?参考 https://baike.baidu.com/item/URI/2901761?fr=aladdinide
if ($request_uri ~ (abc|123)) { return 404; }
curl有不少使用方法,可参考: http://www.javashuo.com/article/p-usdmlmbu-m.html测试