安装nginx的stream模块
stream用于实现TCP和UDP转发,实现端口透传
#解压安装包
tar -zxf nginx-1.24.0.tar.gz
cd nginx-1.24.0
#安装stream模块
./configure --prefix=/usr/local/nginx --with-stream --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module
#如果安装过程遇到报错
checking for OS
+ Linux 3.10.0-1160.el7.x86_64 x86_64
checking for C compiler ... not found
./configure: error: C compiler cc is not found
make: *** No rule to make target `build', needed by `default'. Stop.
#需要安装依赖
yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel
#然后再次安装
./configure --prefix=/usr/local/nginx --with-stream --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module
#编译安装
make && make install
#编译完成后查看安装模块
/usr/local/nginx/sbin/nginx -V
#出现以下内容表示安装完成
nginx version: nginx/1.24.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-stream --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module
#nginx配置文件中添加stream模块
stream {
server {
listen 9092;
#将当前服务器端口9092,转发到172.24.188.141服务器的9092
proxy_pass 172.24.188.141:9092;
}
}
#重新加载配置文件
/usr/local/nginx/sbin/nginx -s reload
#报错
nginx: [emerg] unknown directive "stream" in /usr/local/nginx/conf/nginx.conf:27
#需要在nginx配置文件的第一行添加引入stream模块
load_module /usr/local/nginx/modules/ngx_stream_module.so;
#再次重新加载配置文件,没有报错,安装完成
/usr/local/nginx/sbin/nginx -s reload