前几天通过Tcp_wrappers阻止一些分析出来的恶意IP效果还是有的…不过我后面仍发现会占用一些流量,故此我想通过返回444这种非标准的状态码,减小流量的使用.
默认情况下开启模块仅会返回403,代码如下:
- [root@ipython conf]# curl -I http://www.phpfensi.com
- HTTP/1.1 403 Forbidden
- Server: nginx/1.6.1
- Date: Fri, 15 Aug 2014 14:52:13 GMT
- Content-Type: text/html
- Content-Length: 168
- Connection: keep-alive
那么操作起来很简单了,修改源代码即可,我重新打包后的文件会附在本文末尾附件下载,修改方式很简单,return 对应的状态码即可,代码如下:
- ###重新编译Nginx###
- [root@ipython nginx-1.6.1]# ./configure
- ###具体操作参考前文###
- [root@ipython nginx-1.6.1]# cp objs/nginx /software/nginx/sbin/
- [root@ipython nginx-1.6.1]# make upgrade
再次访问就不返回数据了,代码如下:
- [root@ipython conf]# curl -I http://www.phpfensi.com
- curl: (52) Empty reply from server
- ####Nginx 日志如下####
- 1.1.1.1 - - [15/Aug/2014:23:28:08 +0800] "GET / HTTP/1.1" 444 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 UBrowser/2.0.1144.0 Safari/537.36"
- 1.1.1.1 - - [15/Aug/2014:23:28:09 +0800] "GET / HTTP/1.1" 444 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 UBrowser/2.0.1144.0 Safari/537.36"
- 1.1.1.1 - - [15/Aug/2014:23:28:09 +0800] "GET / HTTP/1.1" 444 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 UBrowser/2.0.1144.0 Safari/537.36"
- 1.1.1.1 - - [15/Aug/2014:23:28:09 +0800] "GET / HTTP/1.1" 444 0 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 UBrowser/2.0.1144.0 Safari/537.36"
|