nginx安装stream模块配置tcp/udp端口转发
下载
wget https://nginx.org/download/nginx-1.18.0.tar.gz
安装依赖
yum -y install gcc gcc-c++ make automake autoconf pcre pcre-devel zlib zlib-devel openssl openssl-devel libtool
配置
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-stream --with-pcre
安装
make && make install
修改配置文件(先备份原始配置)
cd /usr/local/nginx/conf
定义是stream不是http
stream {
upstream tcp6688 {
server 192.168.0.1:6688;
}
server {
listen 6688;
proxy_connect_timeout 30s;
proxy_timeout 24h;
proxy_pass tcp6688;
}
server {
listen 6260;
proxy_connect_timeout 30s;
proxy_timeout 24h;
proxy_pass 192.168.0.1:6260;
}
}
测试、重启
cd /usr/local/nginx/
sbin/nginx -t
启动
sbin/nginx
重启
sbin/nginx -s reload