砖头人:nginx主要用于项目中的静态资源访问请求,以及拦截爬虫类的攻击请求.
//本来想用apache httpd考虑到nginx比较方便配置,就使用nginx了。
1.nginx.conf 配置程序端 由于前期时间域名一直没有通过审核所以,前期使用的是ip访问,后期有了域名后为了支持旧版本以下配置就可支持ip和域名的访问
.........这里为了保护服务器省略其他配置 只留需要被展示的部分
upstream www.brickman.cn{ //代理的域名
server localhost:xx; //转跳指定的tomcat端口项目
}
server {
listen 80;
server_name localhost;
.........
location / {
proxy_pass http://www.brickman.cn; #反向代理域名
.........
}
include agent_deny.conf;#为了防止像性能测试/shell脚本/爬虫类的访问拦截配置
.........
}
server {
listen 80;
server_name img.brickman.cn;#使用域名后的访问
location ~* ^.+\.(jpg|js|html|png|css|apk|ttf|woff|ico)$ {#当访问这些后缀时会访问到特定路径下的静态资源
root xxx;#静态路径
add_header Access-Control-Allow-Origin *;#主要是ttf/woff资源在不同域下会丢失 所以加入这个
access_log on;
expires 30d;#缓存到用户的机器中30天
}
.........
}
server {
listen xxxx;#监听静态端口
server_name 127.0.0.1:xxxx;#之前使用ip的时候的访问
location ~* ^.+\.(jpg|js|html|png|css|apk|ttf|woff|ico)$ {
root /data/img/real;
add_header Access-Control-Allow-Origin *;
access_log on;
expires 30d;
}
}
2.agent_deny.conf 拦截使用的配置
if ($http_user_agent ~* (Scrapy|Curl|HttpClient)) {
return 403;
}
if ($http_user_agent ~ "FeedDemon|JikeSpider|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|YisouSpider|HttpClient|MJ12bot|heritrix|EasouSpider|LinkpadBot|Ezooms|^$" )
{
return 403;
}
if ($request_method !~ ^(GET|HEAD|POST)$) {
return 403;
}
if ($http_user_agent ~ "Mozilla/4.0\ compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727") {
return 404;
}
if ( $http_user_agent ~ "ApacheBench|webBench|Java/|http_load|must-revalidate|wget" ){
return 403;
}
主要缓存以下资源
官网=http://www.brickman.cn
关于我们=http://img.brickman.cn/html/brickman.html
反馈我们=http://img.brickman.cn/html/brickmanback.html
用户头像和事件的压缩图和原图
最重要的是 vi /etc/hosts 中添加需要的域名
127.0.0.1 www.brickman.cn brickman.cn img.brickman.cn
如果此时此刻,你也在北漂、上漂、广漂、深漂,那这里就是你的新家:www.brickman.cn。
欢迎加入砖头人大家庭,现邀请你体验为你定制开发的“砖头人app”。