前幾天通過Tcp_wrappers阻止一些分析出來的惡意IP效果還是有的…不過我後面仍發現會佔用一些流量,故此我想通過返回444這種非標準的狀態代碼,減小流量的使用
預設情況下開啟模組僅會返回403
代碼如下 |
複製代碼 |
[root@ipython conf]# curl -I http://www.111cn.net 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 --prefix=/software/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-google_perftools_module --with-debug --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre=/root/pcre-8.35 --with-openssl=/root/openssl-1.0.1i --with-zlib=/root/zlib-1.2.8 --add-module=./ngx_tcpwrappers ###具體操作參考前文### [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.111cn.net 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" |