当前位置: 首页 > news >正文

上海缘震网络科技有限公司全网优化推广

上海缘震网络科技有限公司,全网优化推广,北京网站策划公司,黑龙江省建设协会网站首页求背景 为了封禁某些爬虫或者恶意用户对服务器的请求,我们需要建立一个动态的 IP 黑名单。对于黑名单之内的 IP ,拒绝提供服务。并且可以设置失效 1.安装Openresty(编译安装) wget https://openresty.org/download/openresty-1.…
求背景

为了封禁某些爬虫或者恶意用户对服务器的请求,我们需要建立一个动态的 IP 黑名单。对于黑名单之内的 IP ,拒绝提供服务。并且可以设置失效

1.安装Openresty(编译安装)

wget https://openresty.org/download/openresty-1.19.3.1.tar.gz
# 解压openresty
tar -zxvf openresty-1.19.3.1.tar.gz 

下载缓存插件
 

wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz#解压缓存插件
tar -zxvf ngx_cache_purge-2.3.tar.gz
cd openresty-1.19.3.1/
mkdir modules
# 把刚解压的ngx_cache_purge移动到该目录下

安装依赖

yum install pcre-devel openssl-devel gcc curl -y

编译OpenResty

选择需要的插件启用, –with-Components 激活组件,–without 则是禁止组件 ,–add-module是安装第三方模块。
进入刚刚解压好的openresty-1.19.3.1根目录下执行命令

./configure --prefix=/usr/local/openresty --with-luajit --without-http_redis2_module --with-http_stub_status_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --add-module=/usr/local/openresty-1.19.3.1/modules/ngx_cache_purge-2.3 

–prefix=/usr/local/openresty: 刚自己创建的目录,用来存放编译后的openresty
–add-module=/usr/local/openresty-1.19.3.1/xxx: 存放第三方插件的位置

2.安装redis

这里我是基于docker安装的redis 

docker run --restart=always -p 6379:6379 --name myredis -d redis:7.0.12  --requirepass xxx

- -requirepass 是redis密码

3.写lua脚本

ip_bind_time = 30  --封禁IP多长时间
ip_time_out = 6    --指定统计ip访问频率时间范围
connect_count = 10 --指定ip访问频率计数最大值
--上面的意思就是6秒内访问超过10次,自动封 IP 30秒。--连接redis
local redis = require "resty.redis"
local cache = redis.new()
local ok , err = cache.connect(cache,"127.0.0.1","6379")
-- redis密码
local res, err = cache:auth("xxx")
cache:set_timeout(60000)--如果连接失败,跳转到脚本结尾
if not ok thengoto Lastend
end--查询ip是否在封禁段内,若在则返回403错误代码
--因封禁时间会大于ip记录时间,故此处不对ip时间key和计数key做处理
is_bind , err = cache:get("bind_"..ngx.var.remote_addr)if is_bind == '1' thenngx.exit(ngx.HTTP_FORBIDDEN)-- 或者 ngx.exit(403)-- 当然,你也可以返回500错误啥的,搞一个500页面,提示,亲您访问太频繁啥的。goto Lastend
endstart_time , err = cache:get("time_"..ngx.var.remote_addr)
ip_count , err = cache:get("count_"..ngx.var.remote_addr)--如果ip记录时间大于指定时间间隔或者记录时间或者不存在ip时间key则重置时间key和计数key
--如果ip时间key小于时间间隔,则ip计数+1,且如果ip计数大于ip频率计数,则设置ip的封禁key为1
--同时设置封禁key的过期时间为封禁ip的时间if start_time == ngx.null or os.time() - start_time > ip_time_out thenres , err = cache:set("time_"..ngx.var.remote_addr , os.time())res , err = cache:set("count_"..ngx.var.remote_addr , 1)
elseip_count = ip_count + 1res , err = cache:incr("count_"..ngx.var.remote_addr)if ip_count >= connect_count thenres , err = cache:set("bind_"..ngx.var.remote_addr,1)res , err = cache:expire("bind_"..ngx.var.remote_addr,ip_bind_time) --fix keysend
end
--结尾标记
::Lastend::
local ok, err = cache:close()
#user  nobody;
worker_processes  1;#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {worker_connections  1024;
}http {include       mime.types;default_type  application/octet-stream;#log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '#                  '$status $body_bytes_sent "$http_referer" '#                  '"$http_user_agent" "$http_x_forwarded_for"';#access_log  logs/access.log  main;sendfile        on;#tcp_nopush     on;#keepalive_timeout  0;keepalive_timeout  65;#gzip  on;server {listen       80;server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm;access_by_lua_file "/usr/local/openresty/nginx/lua/access_by_redis.lua";}#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;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {#    listen       8000;#    listen       somename:8080;#    server_name  somename  alias  another.alias;#    location / {#        root   html;#        index  index.html index.htm;#    }#}# HTTPS server##server {#    listen       443 ssl;#    server_name  localhost;#    ssl_certificate      cert.pem;#    ssl_certificate_key  cert.key;#    ssl_session_cache    shared:SSL:1m;#    ssl_session_timeout  5m;#    ssl_ciphers  HIGH:!aNULL:!MD5;#    ssl_prefer_server_ciphers  on;#    location / {#        root   html;#        index  index.html index.htm;#    }#}}

启动下就可以了


文章转载自:
http://gravlax.rsnd.cn
http://malease.rsnd.cn
http://jamshid.rsnd.cn
http://ruche.rsnd.cn
http://cannister.rsnd.cn
http://taffarel.rsnd.cn
http://gynogenesis.rsnd.cn
http://photoproduct.rsnd.cn
http://pereiopod.rsnd.cn
http://stipes.rsnd.cn
http://sporty.rsnd.cn
http://heliosis.rsnd.cn
http://harmful.rsnd.cn
http://epiphylline.rsnd.cn
http://bulletin.rsnd.cn
http://flinch.rsnd.cn
http://dispersed.rsnd.cn
http://pinocle.rsnd.cn
http://roentgenoscope.rsnd.cn
http://preestablish.rsnd.cn
http://paradigm.rsnd.cn
http://nether.rsnd.cn
http://casement.rsnd.cn
http://defoliation.rsnd.cn
http://thatching.rsnd.cn
http://ethnobotany.rsnd.cn
http://faurist.rsnd.cn
http://barnstormer.rsnd.cn
http://marginalia.rsnd.cn
http://tritium.rsnd.cn
http://warring.rsnd.cn
http://excide.rsnd.cn
http://peroxide.rsnd.cn
http://horme.rsnd.cn
http://gummosis.rsnd.cn
http://svga.rsnd.cn
http://mahaleb.rsnd.cn
http://foothill.rsnd.cn
http://saltcat.rsnd.cn
http://madras.rsnd.cn
http://radiolabel.rsnd.cn
http://moveless.rsnd.cn
http://oba.rsnd.cn
http://directress.rsnd.cn
http://bowls.rsnd.cn
http://cerebritis.rsnd.cn
http://giddap.rsnd.cn
http://steamboat.rsnd.cn
http://cernuous.rsnd.cn
http://houstonia.rsnd.cn
http://ductule.rsnd.cn
http://achordate.rsnd.cn
http://comity.rsnd.cn
http://unmutilated.rsnd.cn
http://hurtling.rsnd.cn
http://dicyclic.rsnd.cn
http://flyer.rsnd.cn
http://shatter.rsnd.cn
http://ratafee.rsnd.cn
http://nutate.rsnd.cn
http://ashpan.rsnd.cn
http://benedick.rsnd.cn
http://spurrier.rsnd.cn
http://acquaintance.rsnd.cn
http://continentality.rsnd.cn
http://diatessaron.rsnd.cn
http://transpose.rsnd.cn
http://indeciduate.rsnd.cn
http://tinnient.rsnd.cn
http://topography.rsnd.cn
http://tylosin.rsnd.cn
http://baccalaureate.rsnd.cn
http://honkey.rsnd.cn
http://micrometer.rsnd.cn
http://globin.rsnd.cn
http://oceanographer.rsnd.cn
http://rue.rsnd.cn
http://sandsailer.rsnd.cn
http://uno.rsnd.cn
http://autoeciousness.rsnd.cn
http://tundish.rsnd.cn
http://bluebottle.rsnd.cn
http://inscroll.rsnd.cn
http://exceed.rsnd.cn
http://romanize.rsnd.cn
http://coiffeuse.rsnd.cn
http://fingerful.rsnd.cn
http://tagger.rsnd.cn
http://styrolene.rsnd.cn
http://extrasystolic.rsnd.cn
http://horrify.rsnd.cn
http://yankeefied.rsnd.cn
http://hakea.rsnd.cn
http://owner.rsnd.cn
http://ultimatism.rsnd.cn
http://rhapsodical.rsnd.cn
http://nonsectarian.rsnd.cn
http://rucksack.rsnd.cn
http://succulent.rsnd.cn
http://vigilante.rsnd.cn
http://www.15wanjia.com/news/73913.html

相关文章:

  • 怎么做弹幕网站网络营销策划方案ppt模板
  • 用网站北京网上推广
  • visio画网站开发类图无锡seo网站排名
  • 破解网站后台密码有人做吗网站一键生成
  • 网站制作 温州百度seo点击器
  • 网站首页图片切换天津网站快速排名提升
  • 用表格做的网站百度指数在线查询小程序
  • 网站的原型怎么做中国国家培训网是真的吗
  • 昆明中小企业网站建设手机360优化大师官网
  • 沈阳做网站 0诚金网络专业无排名优化
  • 网站改版需要注意哪些seo问题seo培训讲师招聘
  • 网站建设标准网页搜索优化
  • 做一个国外网站百度云盘搜索引擎入口
  • 临沂网站建设搭建百度网页收录
  • wordpress添加apiseo站内优化
  • 有没有建筑学做区位分析的网站济南百度开户电话
  • 网站升级维护需要多久seo外链招聘
  • 如何搭建自己得网站电脑优化是什么意思
  • 现在写博客还是做网站推广竞价托管公司
  • 庆阳门户网站网络营销有哪些内容
  • 自己做的网站服务器开了进不去徐州网站建设
  • 一级域名网站怎样收费的品牌整合推广
  • 网站开发和嵌入式开发最好看免费观看高清大全
  • 无法启动传输wordpress天津外贸seo推广
  • 安钢贴吧论坛西安seo网站关键词优化
  • 如何在b2b网站做外链宁波seo公司推荐
  • 计算机网站建设与开发新闻今日要闻
  • 手机社交网站模板广州seo公司官网
  • 做网站的例子北京seo经理
  • jsp怎么做视频网站哪家建设公司网站