需求:
A主機(192.168.5.2)到B主機網(wǎng)絡(luò)通缠借,B到C主機(172.18.4.15)網(wǎng)路通胁黑,要從A訪問C的端口30000-31000
方案1. 在B上修改iptables昙啄,失敗巴比,沒搞明白适荣。
方案2. B上有openresty噪生,配置4層代理阵翎,30000端口測試成功
stream listen 可以支持端口段逢并,格式 xxx-xxx , 但需要 1.15.10 之后的版本
最新的openresty是1.15.8.1,基于nginx 1.15.8 core郭卫,不支持砍聊。只能重新再裝個nginx
源碼安裝1.16.0 nginx
mkdir /home/nginx
cd /home/nginx
// 下載最新版本 nginx-1.16.0.tar.gz,解壓贰军,重命名為nginx-1.16.0-src
wget https://nginx.org/download/nginx-1.16.0.tar.gz
tar -zxf nginx-1.16.0.tar.gz
mv nginx-1.16.0 nginx-1.16.0-src
// 下載依賴的pcre(rewrite模板依賴)pcre-8.43.tar.gz 和 zlib (gzip依賴)zlib-1.2.11.tar.gz玻蝌, 解壓
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
tar zxf pcre-8.43.tar.gz
wget http://zlib.net/zlib-1.2.11.tar.gz
tar zxf zlib-1.2.11.tar.gz
cd nginx-1.16.0-src
./configure --prefix=/home/nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-stream --with-debug --with-pcre=../pcre-8.43 --with-zlib=../zlib-1.2.11
make && make install
./sbin/nginx 啟動
編輯conf/nginx.conf
stream {
server {
allow 192.168.5.2;
listen 30000-31000;
proxy_pass 172.18.4.15:$proxy_port;
}
}
重啟nginx
./sbin/nginx -t
./sbin/nginx -s reload