nginx通过stream模块实现反向代理
下载nginx包,具体版本查看Nginx官方下载地址。
wget http://nginx.org/download/nginx-1.17.10.tar.gz
一些编译安装要用到的依赖包
yum -y install gcc gcc-c++ make pcre-devel zlib-devel openssl-devel
openssl-devel(用于加密)
nginx从1.9.0开始,新增加了一个stream模块,用来实现四层协议的转发、代理或者负载均衡等。
默认安装的nginx是没有开启stream模块的,需要在安装时添加,如果已经安装了,后续安装的话,请看这篇文章NGINX的后续模块添加。
在nginx的解压包里执行,已添加了stream模块
./configure --prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gzip_static_module \
--with-stream \
--with-stream_ssl_module && make && make install
然后修改配置文件
vi /usr/local/nginx/conf/nginx.conf
#已省略无关部分
events {
worker_connections 1024;
}
#如有需要可添加多个server
stream{
log_format proxy '$remote_addr [$time_local] '
'$protocol $status $bytes_sent $bytes_received '
'$session_time -> $upstream_addr '
'$upstream_bytes_sent $upstream_bytes_received $upstream_connect_time';
access_log logs/tcp-access.log proxy;
server{
listen 12345 so_keepalive=on; #监听本机12345端口
proxy_pass 172.14.15.16:12345; #转发到该ip的12345端口
}
}
http {
include mime.types;
default_type application/octet-stream;
本帖子也是纯手工制作,转载请标明出处-----------burukku(づ。◕ᴗᴗ◕。)づ