天天看點

編譯Nginx支援Tcp_wrappers編譯Nginx支援Tcp_wrappers

務提供了增強的安全性。tcp wrappers是一種對使用 /etc/inetd.sec 的替換方法。tcp wrappers 提供防止主機名和主機位址欺騙的保護。欺騙是一種僞裝成有效使用者或主機以獲得對系統進行未經授權的通路的方法。
編譯Nginx支援Tcp_wrappers編譯Nginx支援Tcp_wrappers

1、重新編譯nginx

[root@ipython nginx-1.6.1]# tar zxf ../ngx_tcpwrappers.tar.gz -c ./

[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]# sed -i s'#cflags = -pipe -o -w -wall -wpointer-arith -wno-unused-parameter -werror#cflags = -pipe -o -w -wall -wpointer-arith -wno-unused-parameter -g#' objs/makefile

####不要make install 哦,編譯好即可####

[root@ipython nginx-1.6.1]# make

2、完成更新,以及子產品的使用,nginx還是很奇特的哦~~

####備份可執行檔案,複制新的檔案####

[root@ipython nginx-1.6.1]# mv /software/nginx/sbin/nginx /software/nginx/conf/@nginx

[root@ipython nginx-1.6.1]# cp objs/nginx /software/nginx/sbin/

####測試新版本的nginx####

[root@ipython nginx-1.6.1]# /software/nginx/sbin/nginx -t

nginx: the configuration file /software/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /software/nginx/conf/nginx.conf test is successful

###此時沒有加入tcp_wrappers的配置 測試下通路###

[root@ipython openssl-1.0.1i]# curl -i http://www.ipython.me

http/1.1 200 ok

server: nginx/1.6.1

date: mon, 11 aug 2014 23:08:08 gmt

content-type: text/html

content-length: 612

last-modified: mon, 11 aug 2014 22:45:25 gmt

connection: keep-alive

etag: "53e94785-264"

accept-ranges: bytes

###平滑更新###

[root@ipython nginx-1.6.1]# make upgrade

##測試子產品,拒絕1.1.1.30的nginx請求## ##在http塊裡加入如下配置##

tcpwrappers on;

tcpwrappers_daemon nginx;

tcpwrappers_thorough off;

##hosts.deny如下##

[root@ipython nginx-1.6.1]# awk '!/^#/' /etc/hosts.deny

nginx:1.1.1.30

##重新讀取nginx配置檔案##

[root@ipython nginx-1.6.1]# /software/nginx/sbin/nginx -s reload

###此時通路 就是403了###

[root@itchenyi ~]# curl -i http://www.ipython.me

http/1.1 403 forbidden

date: mon, 11 aug 2014 23:12:47 gmt

content-length: 168

3、tcp_warppers 子產品指令

###ngx_tcp_wrappers 配置指令###

1、tcpwrappers

文法 : tcpwrappers [on|off]

預設值 : tcpwrappers off

作用域 : http, server, location, limit_except

描述 : 子產品的開關,開啟則使用tcp wrappers 進行通路控制,關閉以避免浪費性能

2、tcpwrappers_daemon

文法 : tcpwrappers_daemon name

預設值 : tcpwrappers_daemon nginx

描述 : 該名字的定義用于在/etc/hosts.[allow|deny]識别

3、tcpwrappers_thorough

文法 : tcpwrappers_thorough [on|off]

預設值 : tcpwrappers_thorough off

描述 : 基于hosts.ctl以檢查使用ip位址、使用者名、反向dns解析,子產品的開發者也未提供詳細的使用說明

 原文釋出時間:2014-08-17

本文來自雲栖合作夥伴“linux中國”

繼續閱讀