您好,登錄后才能下訂單哦!
這篇文章主要為大家展示了“linux如何禁止頻繁訪問的ip訪問nginx”,內容簡而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領大家一起研究并學習一下“linux如何禁止頻繁訪問的ip訪問nginx”這篇文章吧。
實驗環境
版本:redhat6.5
ip:172.16.1.100,172.16.10
軟件:nginx
172.16.1.10部署nginx
[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
測試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
nginx 可以正常訪問。
接下來,假設172.16.1.100是黑客主機,頻繁訪問nginx服務
模擬172.16.1.100訪問10次172.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 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)
查看nginx日志
172.16.1.10
[root@localhost ~]# tail /usr/local/nginx/logs/access.log172.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.10curl: (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.10HTTP/1.1 403 ForbiddenServer: nginx/1.11.2Date: Sat, 25 Jul 2020 23:12:06 GMTContent-Type: text/htmlContent-Length: 169Connection: keep-alive
以上是“linux如何禁止頻繁訪問的ip訪問nginx”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。