以上就是两种简单的方法限制ip访问,还有许多方法可以利用工具进行ip限制。
[root@localhost ~]# curl -I 172.16.1.10HTTP/1.1 403 ForbiddenServer: nginx/1.11.2Date: Sat, 25 Jul 2020 23:12:06 GMTContent-Type: text/htmlContent-Length: 169Connection: keep-alive
172.16.1.10
172.16.1.100
此时172.16.1.100再也不能访问nginx
[root@localhost ~]# curl 172.16.1.10curl: (7) Failed connect to 172.16.1.10:80; 连接超时
172.16.1.100
[root@localhost ~]# iptables -I INPUT -s 172.16.1.100 -ptcp --dport 80 -j DROP
172.16.1.10
由此可见,一秒钟之内172.16.1.100访问了nginx10次,接下来禁止掉这个问题ip
[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.10
[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).....doneServer Software: nginx/1.11.2Server Hostname: 172.16.1.10Server Port: 80Document Path: /Document Length: 612 bytesConcurrency Level: 1Time taken for tests: 0.016 secondsComplete requests: 10Failed requests: 0Write errors: 0Total transferred: 8450 bytesHTML transferred: 6120 bytesRequests 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] receivedConnection Times (ms) min mean[+/-sd] median maxConnect: 0 1 0.3 0 1Processing: 1 1 0.3 1 2Waiting: 0 1 0.3 1 1Total: 1 1 0.5 1 2ERROR: 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)
172.16.1.100
nginx 可以正常访问。
接下来,假设172.16.1.100是黑客主机,频繁访问nginx服务
[root@localhost ~]# curl -I 172.16.1.100HTTP/1.1 200 OKServer: nginx/1.11.2Date: Mon, 17 Aug 2020 09:36:29 GMTContent-Type: text/htmlContent-Length: 15Last-Modified: Mon, 17 Aug 2020 09:36:19 GMTConnection: keep-aliveETag: "5f3a4f93-f"Accept-Ranges: bytes
[root@localhost tools]# lsnginx-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]# lsnginx-1.11.2 nginx-1.11.2.tar.gz[root@localhost tools]# cd nginx-1.11.2[root@localhost nginx-1.11.2]# lsauto 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
实验环境:
版本:redhat6.5
ip:172.16.1.100,172.16.10
软件:nginx
文章:
在现代社会中,信息技术(IT)的重要性愈发凸显。IT基础培训课程成为越来越多人迈向成功的关键一步。掌握IT基础知识不仅可以帮助我们适应快速发展的数字时代,还能为我们的职业生涯打下坚实的基础。
在进行IT基础培训课程时,有几个关键要素是不可忽视的。首先,课程的内容应该全面且系统化。IT领域庞杂而复杂,涉及到多个领域和技术。一个优质的IT基础培训课程应该囊括计算机基础、编程语言、网络基础、数据库管理等内容,使学习者能够全面理解IT的核心概念和技术。
其次,实践是学习IT基础的重要环节。理论知识的学习固然重要,但只有通过实际动手操作,才能真正巩固所学的知识。一个优秀的IT基础培训课程应该提供充足的实践机会,让学生亲自动手解决问题,编写代码,配置网络等等。通过实践,学生可以培养问题解决的能力和实际操作的技巧。
此外,一个良好的学习环境对于IT基础培训课程的成功也是至关重要的。一个充满活力和创造力的学习环境可以激发学生的学习兴趣和动力。这包括合适的学习设施和设备,以及热情且有经验的教师和辅导员。学生们需要一个支持性的环境,在这里他们可以自由地提问、交流和合作。
此外,及时反馈也是一个有效的学习机制。学生们在学习IT基础的过程中,难免会遇到问题和困惑。一个优秀的IT基础培训课程应该提供及时的反馈机制,让学生可以获得专业的指导和建议。这可以通过定期的考试和作业,以及个别辅导等形式实现。及时的反馈可以帮助学生及早发现和纠正问题,提高学习效果。