ICE.ICE|

韩憨

园龄:4年7个月粉丝:42关注:47

linux安全篇:禁止频繁访问的ip访问nginx

实验环境

 

版本:redhat6.5
ip:172.16.1.100,172.16.10
软件:nginx

172.16.1.10部署nginx

 

[root@localhost tools]# ls
nginx-1.11.2.tar.gz
[root@localhost tools]# yum  install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
[root@localhost tools]# tar xf nginx-1.11.2.tar.gz 
[root@localhost tools]# ls
nginx-1.11.2  nginx-1.11.2.tar.gz
[root@localhost tools]# cd nginx-1.11.2
[root@localhost nginx-1.11.2]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[root@localhost nginx-1.11.2]# ./configure
[root@localhost nginx-1.11.2]# make
[root@localhost nginx-1.11.2]# make install

 

测试nginx服务

 

[root@localhost ~]# curl -I 172.16.1.100
HTTP/1.1 200 OK
Server: nginx/1.11.2
Date: Mon, 17 Aug 2020 09:36:29 GMT
Content-Type: text/html
Content-Length: 15
Last-Modified: Mon, 17 Aug 2020 09:36:19 GMT
Connection: keep-alive
ETag: "5f3a4f93-f"
Accept-Ranges: bytes

 

nginx 可以正常访问。
接下来,假设172.16.1.100是黑客主机,频繁访问nginx服务

模拟172.16.1.100访问10172.16.1.10

 

172.16.1.100

[root@localhost ~]# ab -c 1 -n 10 http://172.16.1.10/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking 172.16.1.10 (be patient).....done


Server Software:        nginx/1.11.2
Server Hostname:        172.16.1.10
Server Port:            80

Document Path:          /
Document Length:        612 bytes

Concurrency Level:      1
Time taken for tests:   0.016 seconds
Complete requests:      10
Failed requests:        0
Write errors:           0
Total transferred:      8450 bytes
HTML transferred:       6120 bytes
Requests per second:    617.02 [#/sec] (mean)
Time per request:       1.621 [ms] (mean)
Time per request:       1.621 [ms] (mean, across all concurrent requests)
Transfer rate:          509.16 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1   0.3      0       1
Processing:     1    1   0.3      1       2
Waiting:        0    1   0.3      1       1
Total:          1    1   0.5      1       2
ERROR: The median and mean for the initial connection time are more than twice the standard
       deviation apart. These results are NOT reliable.

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      2
  90%      2
  95%      2
  98%      2
  99%      2
 100%      2 (longest request)

 

查看nginx日志

 

172.16.1.10

[root@localhost ~]# tail /usr/local/nginx/logs/access.log
172.16.1.100 - - [26/Jul/2020:05:58:24 +0800] "GET / HTTP/1.0" 200 612 "-" "ApacheBench/2.3"
172.16.1.100 - - [26/Jul/2020:05:58:24 +0800] "GET / HTTP/1.0" 200 612 "-" "ApacheBench/2.3"
172.16.1.100 - - [26/Jul/2020:05:58:24 +0800] "GET / HTTP/1.0" 200 612 "-" "ApacheBench/2.3"
172.16.1.100 - - [26/Jul/2020:05:58:24 +0800] "GET / HTTP/1.0" 200 612 "-" "ApacheBench/2.3"
172.16.1.100 - - [26/Jul/2020:05:58:24 +0800] "GET / HTTP/1.0" 200 612 "-" "ApacheBench/2.3"
172.16.1.100 - - [26/Jul/2020:05:58:24 +0800] "GET / HTTP/1.0" 200 612 "-" "ApacheBench/2.3"
172.16.1.100 - - [26/Jul/2020:05:58:24 +0800] "GET / HTTP/1.0" 200 612 "-" "ApacheBench/2.3"
172.16.1.100 - - [26/Jul/2020:05:58:24 +0800] "GET / HTTP/1.0" 200 612 "-" "ApacheBench/2.3"
172.16.1.100 - - [26/Jul/2020:05:58:24 +0800] "GET / HTTP/1.0" 200 612 "-" "ApacheBench/2.3"
172.16.1.100 - - [26/Jul/2020:05:58:24 +0800] "GET / HTTP/1.0" 200 612 "-" "ApacheBench/2.3"

 

由此可见,一秒钟之内172.16.1.100访问了nginx10次,接下来禁止掉这个问题ip

通过iptables限制ip访问

 

172.16.1.10

[root@localhost ~]# iptables -I INPUT -s 172.16.1.100 -ptcp --dport 80 -j DROP

172.16.1.100

[root@localhost ~]# curl 172.16.1.10
curl: (7) Failed connect to 172.16.1.10:80; 连接超时

此时172.16.1.100再也不能访问nginx

nginx配置文件限制

 

172.16.1.10

 

 

 


172.16.1.100

[root@localhost ~]# curl -I 172.16.1.10
HTTP/1.1 403 Forbidden
Server: nginx/1.11.2
Date: Sat, 25 Jul 2020 23:12:06 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive

本文作者:韩憨

本文链接:https://www.cnblogs.com/hanby/p/14253021.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   韩憨  阅读(554)  评论(0编辑  收藏  举报
//看板娘

剑桥

评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 隔离 (Studio Live Duet) 陈凯咏,林家谦
  2. 2 明知做戏 吴雨霏
  3. 3 残酷游戏 卫兰
  4. 4 你,好不好? 周兴哲
  5. 5 我可以 蔡旻佑
  6. 6 云烟成雨 房东的猫
  7. 7 说散就散 JC 陈咏桐
  8. 8 我配不上你 夏天Alex
  9. 9 不再联系 夏天Alex
  10. 10 等我先说 夏天Alex
  11. 11 我知道他爱你 夏天Alex
  12. 12 多想在平庸的生活拥抱你 隔壁老樊
  13. 13 这一生关于你的风景 隔壁老樊
  14. 14 我曾 隔壁老樊
  15. 15 关于孤独我想说的话 隔壁老樊
  16. 16 过客 周思涵
  17. 17 备爱 周思涵
  18. 18 嚣张 en
  19. 19 海口 后弦
明知做戏 - 吴雨霏
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作词 : Xia Zhi

作曲 : Fong Man Leung

编曲 : 吴国恩

监制 : Gary Chan

等你的汽水喝一半给你加片薄冰

等你的桌面满泻我总会打理重整

不想纯情 不够聪明

你未发现我的身影

得我帮你依照编码整理家里电影

得我帮你依照编码整理家里电影

只会得我一个帮你选购喜爱铃声

天天如常 估你心情

等一个眼神求证 一闪擦过如流星

怎么我为我做过的感到惊怕

就像爱吗我也不肯定恐怕

我以为存在吗 千变万化

从来不肯开口可相信吗 离谱吗

请你不要阻我喜欢你

明明是爱但你未说话你扮作闪避

这个沉默冷静的你毫无办法处理

其实我亦怕是错摸心理

总有天会等到好天气

游行示爱大叫着你在某大片草地

等你无用退避不过仍然害羞的你

还是顾忌太不争气 明知做戏

即使你未太在意不感到惊讶

即使你未太在意不感到惊讶

现在要说爱你请准备招架

勇气还存在吗 不要害怕

随时真的胆敢亲手送花 离谱吗

请你不要阻我喜欢你

明明是爱但你未说话你扮作闪避

这个沉默冷静的你亳无办法处理

其实我亦怕是错摸心理

总有天会等到好天气

游行示爱大叫着你在某大片草地

等你无用退避不过仍然害羞的你

还是顾忌太不争气 明知做戏

不过不要阻我紧张你

如何令你愉快让我办妥为你准备

喜爱沉默冷静的你还是自信的你

仍愿意为你造一些惊喜

总有天会等到好天气

游行示爱大叫着你在某大片草地

等你无用退避不过途人目光不理

期待贴着你的手臂 无须做戏

等你喜爱等你不爱就凭摘毫验证

等你喜爱等你不爱就凭摘毫验证

想爱不爱偏爱不理亦同样难划清

天天如常 估你心情

不想扑索来求证 争取过趁还年青

终于你下决定来答应 太动听

点击右上角即可分享
微信分享提示